24. Bash Shell - Text Processing Intermediate Level (1)
Contents
We continue to use the file file.txt test data we used in Entry Level post:
Word Counter
The wc command by default outputs the number of newlines, words, and bytes of the file:
|
|
Byte Counts
We can add the -c or –bytes parameter to output the file’s byte counts:
|
|
Character Counts
We can add the -m or –chars parameter to output the file’s character counts:
|
|
Word Counts
We can add the -w or –words parameter to output the file’s word counts:
|
|
Newline Counts
We can add the -l or –lines parameter to output the file’s line counts:
|
|
Sorted Result
Sorts One File Contents in Ascending Order
We can use the sort command to sort the letters of the file contents:
|
|
Sorts Multiple File Contents in Ascending Order
We can sort multiple files at the same time:
|
|
Sorts Contents in Descending Order
We can add the -r or –reverse parameter to sort the contents of the file in descending order:
|
|
Sorts Numeric Contents in Ascending Order
Before we start, we need to prepare a file with numeric contents:
|
|
We can add the -n, –numeric-sort or –sort=numeric parameter to sort the integer number of the file contents in ascending order.
|
|
Sorts Numeric Contents in Descending Order
We can add the -n, –numeric-sort or –sort=numeric with a -r or –reverse parameter to sort the integer number of the file contents in ascending order.
|
|
References 6.1 wc: Print newline, word, and byte counts, 7.1 sort: Sort text files
If you think the content of this article has helped you, and if you would like some more high-quality materials in the near future, please give me some modest support.
Author Dong Chen
LastMod Mon Feb 25 2019