[Examples] Useful ’sed’ examples


sed G myfile.txt > newfile.txt

Double-spaces the contents of file myfile.txt, and writes the output to the filenewfile.txt.

sed = myfile.txt | sed 'N;s/\n/\. /'

Prefixes each line of myfile.txt with a line number, a period, and a space, and displays the output.

sed 's/test/example/g' myfile.txt > newfile.txt

Searches for the word "test" in myfile.txt and replaces every occurrence with the word "example".

sed -n '$=' myfile.txt

Counts the number of lines in myfile.txt and displays the results.

sed -i.bak '/text/d' myfile.txt

Removes all lines containing 'text' from myfile.txt



Attached Files
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Security Code Security Code
Related Articles RSS Feed
[How To] Remove a disk from a LVM volume group
Viewed 2801 times since Thu, May 4, 2017