Delete a specified row in linux

Source: Internet
Author: User
Delete a specified row in linux #! /Bin/shFILENAMEfile.txt # it can be changed to $ 1if [! -Ffile.txt]; thenecho & quot; $ FILENAMEnofound & quot; exit1www. 2cto. comfiecho-n & quot; INPUTSOMETHING: & quot; read...
Delete a specified row in linux #! /Bin/shFILENAME=file.txt # it can be changed to $1 if [! -F file.txt]; then echo "$ FILENAME no found" exit 1 www.2cto.com fiecho-n "input some thing:" readif [! -Z "$ REPLY"]; then INFO = $ (grep $ reply filename) if [! -Z "$ INFO"]; then sed-I-e '/$ REPLY/d' FILENAME # delete this line only. else echo "no information specified" exit 1 fielse echo "input some thing" exit 1 fiexit $? 1. ============== "add a line with sed specified in the middle of the document and then add a line. sometimes we use scripts to modify the document, for example, add or remove a line of echo "1"; echo "2"; echo "4"; echo "5"; in the preceding example "; append the echo "3"; you can use the following command sed-I '/echo \ "2 \";/a \ echo \ "3 \"; 'test. sh uses a semicolon because it is already in the text. That is to say, the semicolon is not required! Abstract: sed-I '/*/a *' filename 2. ================ "delete a row of content from the sed file

Http://topic.csdn.net/u/20080410/23/0c081d7c-85ab-4032-a536-d3bd8d55de8d.html Linux shell script to delete a line of content in the file such as: in 1.txt has the following content: HELLO = 1 www.2cto.com NI = 2 WORLD = 3I Love China. love all .... to delete the third row: sed-I '3D '1.txt if you delete the sed-I'/^ Love/d' 1.txt line starting with Love, delete the sed-I '/Love/d' 1.txt line containing Love. author gzh0222

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.