Shell Exercises (v)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.