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

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
主站蜘蛛池模板: 辽阳县| 本溪| 阳新县| 定兴县| 环江| 玉环县| 彭泽县| 元朗区| 浠水县| 西昌市| 阳东县| 綦江县| 武胜县| 黎川县| 天津市| 道真| 称多县| 合阳县| 兰西县| 临江市| 商丘市| 高雄市| 吉林市| 永春县| 公安县| 信阳市| 乌兰察布市| 襄垣县| 沂南县| 临沭县| 十堰市| 淮滨县| 龙岩市| 江西省| 乐山市| 甘孜县| 东海县| 龙州县| 河南省| 老河口市| 宽城|