- 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
推薦閱讀
- 微服務設計(第2版)
- Vue.js快跑:構建觸手可及的高性能Web應用
- Blockly創意趣味編程
- Hands-On Functional Programming with TypeScript
- RISC-V體系結構編程與實踐(第2版)
- Android應用案例開發大全(第二版)
- Android嵌入式系統程序開發:基于Cortex-A8(第2版)
- 網絡數據采集技術:Java網絡爬蟲實戰
- Backbone.js Testing
- Application Development with Parse using iOS SDK
- UML基礎與Rose建模實用教程(第三版)
- MongoDB Cookbook
- Swift iOS Programming for Kids
- 設計模式之禪
- vSphere High Performance Cookbook(Second Edition)