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

  • Bash Cookbook
  • Ron Brash Ganesh Naik
  • 174字
  • 2021-07-23 19:17:39

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
主站蜘蛛池模板: 满城县| 贡觉县| 泸溪县| 常熟市| 乡宁县| 塘沽区| 临夏市| 武宣县| 和龙市| 中西区| 嘉义市| 华蓥市| 灌南县| 边坝县| 长岭县| 宾阳县| 湖南省| 突泉县| 上栗县| 崇州市| 博湖县| 保亭| 辉南县| 昭觉县| 巩留县| 延长县| 武山县| 龙口市| 龙州县| 绵阳市| 达孜县| 武定县| 天水市| 广西| 特克斯县| 贺兰县| 格尔木市| 蒙山县| 荣昌县| 巫山县| 香港|