Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"sed" command in bash

Could someone explain this command for me:

cat | sed -e 's,%,$,g' | sudo tee /etc/init.d/dropbox << EOF    echo "Hello World" EOF 

What does the "sed" command do?

like image 886
ajsie Avatar asked Oct 21 '10 06:10

ajsie


People also ask

What is sed command in bash?

The SED command in Linux stands for Stream EDitor and is helpful for a myriad of frequently needed operations in text files and streams. Sed helps in operations like selecting the text, substituting text, modifying an original file, adding lines to text, or deleting lines from the text.

How do you use sed?

Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.txt.

What is the use of sed in Unix?

SED command in UNIX stands for stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace.


1 Answers

sed is the Stream EDitor. It can do a whole pile of really cool things, but the most common is text replacement.

The s,%,$,g part of the command line is the sed command to execute. The s stands for substitute, the , characters are delimiters (other characters can be used; /, : and @ are popular). The % is the pattern to match (here a literal percent sign) and the $ is the second pattern to match (here a literal dollar sign). The g at the end means to globally replace on each line (otherwise it would only update the first match).

like image 139
Jack Kelly Avatar answered Sep 20 '22 18:09

Jack Kelly