10 productivity-Boosting bash techniques

Source: Internet
Author: User


① add a line to the top of the file with sed:

Sed-i ' 1s/^/added line \n/' filename

Note: sed-i ' 1s/^/added line/' filename, no \ n ' means adding a sentence before the first line of the file

such as: Comment out the first line sed-i ' 1s/^/#/' filename

② inserting multiple rows of data into a file using the command line:

Cat >> filename << EOF

Xxxxxxxxxxxxxxxxxxx

Xxxxxxxxxxxxxxxxxx

Xxxxxxxxxxxxxxxxx

Eof

Note: EOF is a shorthand for end of file, inserting data between two EOF into a file

③ use Find and sed to manipulate files:

Find.         -type f-name ' *.txt '-exec sed-i ' s/jeff/tom/g ' {} \; Find the file at the end of the current directory and replace Jeff in the file with Tom

Note: You can create a function in the script file, such as:

function find_sed

{

Find. -type f-name ' *.txt '-exec sed-i ' s/$1/$2/g ' {} \;

}

Find_sed Jeff Tom #调用函数 and passed in two external variables Jeff and Tom



For more information see this link: http://www.techug.com/ten-tips-for-wonderful-bash-productivity














This article from "See" blog, declined reprint!

10 productivity-Boosting bash techniques

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.