官术网_书友最值得收藏!

How to do it...

We have already seen most of these concepts already and even wc itself in one of the previous recipes, so let's get started:

  1. Open a terminal and run the following commands:
$ wc -l testdata/duplicates.txt
$ wc -c testdata/duplicates.txt
  1. As you may have noticed, the output has the filename included. Can we remove it with AWK? Absolutely, but we can also remove it with a command called cut. The -d flag stand, for delimiter and we would like to have a field (specified by -f1):
$ wc -c testdata/duplicates.txt | cut -d ' ' -f1
$ wc -c testdata/duplicates.txt | awk '{ print $1 }'
  1. Imagine that we have a massive file full of strings. Could we reduce the returned results? Of course, but let's use the sort command first to sort the elements contained in testdata/duplicates.txt and then use sort to produce a list of only the unique elements:
$ sort testdata/duplicates.txt
$ sort -u testdata/duplicates.txt
$ sort -u testdata/duplicates.txt | wc -l
主站蜘蛛池模板: 新干县| 砀山县| 威远县| 平谷区| 永济市| 邵东县| 茶陵县| 邹城市| 遂昌县| 同仁县| 民勤县| 通海县| 罗江县| 文化| 商丘市| 苍梧县| 兴化市| 潼关县| 旌德县| 镇安县| 井研县| 乐清市| 阿坝县| 紫云| 富川| 沙湾县| 宜兰县| 自贡市| 竹北市| 汨罗市| 得荣县| 金坛市| 金川县| 永安市| 通海县| 南开区| 鄂尔多斯市| 德江县| 密云县| 营口市| 乌兰浩特市|