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

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
主站蜘蛛池模板: 青铜峡市| 尉氏县| 读书| 原平市| 千阳县| 新密市| 萝北县| 称多县| 清流县| 临沧市| 九江县| 兴业县| 巴楚县| 桐城市| 钟山县| 筠连县| 昆山市| 正阳县| 社会| 蓝田县| 延边| 绥棱县| 宜黄县| 渝北区| 喜德县| 苗栗县| 彩票| 门头沟区| 赤城县| 建平县| 宁波市| 农安县| 武清区| 惠水县| 铁岭市| 宜君县| 吴江市| 叶城县| 缙云县| 乌什县| 山东省|