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:

The contents of the file.txt file
Word Counter
The wc command by default outputs the number of newlines, words, and bytes of the file:
|
|

Outputs the length of the newlines, words and bytes of the file.txt file
Byte Counts
We can add the -c or –bytes parameter to output the file’s byte counts:
|
|

Outputs the byte counts of file.txt file
Character Counts
We can add the -m or –chars parameter to output the file’s character counts:
|
|

Outputs the char counts of file.txt file
Word Counts
We can add the -w or –words parameter to output the file’s word counts:
|
|

Outputs the word counts of file.txt file
Newline Counts
We can add the -l or –lines parameter to output the file’s line counts:
|
|

Outputs the line counts of file.txt file
Sorted Result
Sorts One File Contents in Ascending Order
We can use the sort command to sort the letters of the file contents:
|
|

Outputs the sorted contents of the file.txt file
Sorts Multiple File Contents in Ascending Order
We can sort multiple files at the same time:
|
|

Outputs the sorted contents of the file.txt file
Sorts Contents in Descending Order
We can add the -r or –reverse parameter to sort the contents of the file in descending order:
|
|

Outputs the reversed sorted contents of the file.txt file
Sorts Numeric Contents in Ascending Order
Before we start, we need to prepare a file with numeric contents:
|
|

Save a few lines of integer numbers to the num_file file
We can add the -n, –numeric-sort or –sort=numeric parameter to sort the integer number of the file contents in ascending order.
|
|

Output digital contents in
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.
|
|

Output digital contents in
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