Exercise 1:Delete the letters in the text
Requirements: Delete the line containing the letters in the first 5 lines of a text document and delete all the letters from 6 to 10 lines (file 1.txt, lines greater than 10 lines)
Reference Answer:
#!/bin/bash#date:2018 February 9 sfile= "/root/2.txt" n= ' cat $sfile |wc-l ' for i in ' SEQ 1 5 ' Do sed-n "$i" P $sfile |grep-v ' [A-za -Z] ' donefor i in ' seq 6 ' does sed-n "$i" P $sfile |sed ' s/[a-za-z]//g ' donefor i in ' seq one $N ' do sed-n ' $i "p $sfiledon E
Exercise 2: finding words with fewer than 6 letters
Requirements: use the shell to print a word in the following sentence that has less than 6 alphabetic characters: Bash also interprets a number of multi-character options.
Reference Answer:
#!/bin/bash# date:2018 February 9 str= "Bash also interprets a number of multi-character options." For work in $strdo len= ' echo ' $work "|wc-l" if [$len-lt 6];then Echo $work fidone
Shell Exercises (v)