- 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:
- Open a terminal and run the following commands:
$ wc -l testdata/duplicates.txt
$ wc -c testdata/duplicates.txt
- 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 }'
- 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
推薦閱讀
- 復雜軟件設計之道:領域驅動設計全面解析與實戰
- Python 深度學習
- 少年輕松趣編程:用Scratch創作自己的小游戲
- 微信小程序項目開發實戰
- BeagleBone Black Cookbook
- 深度學習:Java語言實現
- Test-Driven Development with Django
- 時空數據建模及其應用
- 深度學習入門:基于Python的理論與實現
- Java Web開發教程:基于Struts2+Hibernate+Spring
- 現代C++語言核心特性解析
- Java EE程序設計與開發實踐教程
- 虛擬現實:引領未來的人機交互革命
- 3D Printing Designs:Design an SD Card Holder
- C語言程序設計實驗指導教程