- 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快樂編程:人工智能深度學習基礎
- NativeScript for Angular Mobile Development
- Django Design Patterns and Best Practices
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- Python數據可視化之Matplotlib與Pyecharts實戰
- Python漫游數學王國:高等數學、線性代數、數理統計及運籌學
- GameMaker Essentials
- Visual Studio Code 權威指南
- 跟戴銘學iOS編程:理順核心知識點
- Java Web動態網站開發(第2版·微課版)
- Oracle SOA Suite 12c Administrator's Guide
- ANSYS FLUENT 16.0超級學習手冊
- C語言王者歸來
- ASP.NET Core 2 High Performance(Second Edition)
- C#從入門到精通(微視頻精編版)