Shell: Day #2
Today run through the commands to process the Text streams from the shell.
- less – command let you show less content from the file you are viewing.
- sort – helps you sort the output, -f let you do sort case-insensitive and -n numerical sort.
- cut – help to select the fields(-f)/character(-c)
- fmt – format the output of the file, you can specify the width with -w
- tac – similar to the cat command but in reverse
- sed- this command use to process each line of file with a script
let see these command in action
>> less hello.txt
Hello World
THis is a text file
hello.txt (END)
>> cat shopping_list
cucumber
bread
fish fingers
>> sort shopping_list
bread
cucumber
fish fingers
>>date
Thu Jul 9 00:21:17 IST 2020
>>date | cut -d " " -f1
Thu
>>cat COPYING | less
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
>> cat COPYING | less | fmt -w 30
The GNU General Public
License does not permit
incorporating your program
>>cat copybump.py
#! /usr/bin/env python3
import datetime
import os
import re
import stat
import sys
...
if __name__ == '__main__':
do_walk()
>> tac copybump.py
do_walk()
if __name__ == '__main__':
...
import sys
import stat
import re
import os
import datetime
#! /usr/bin/env python3
>> sed -f spelling.sed < report.txt > corrected.txt # correct the spellling mistake in report.txt and output the correct text in corrected.txt