Sunday, June 28, 2009

Text Conversion with sed

sed is a handy UNIX tool that manipulates a stream of text. Here I'll list some useful examples of sed commands. This is just a note to myself. I'll add more as I learn more about sed

To replace every instance of ABC with DEF in a text file, run the following command:

sed 's/ABC/DEF/g' input.txt > output.txt

To convert DOS/WINDOWS style text to UNIX/LINUX style text, run the following command. In other words, this command removes carriage returns from the end of every line:

sed 's/\r$//g' input.txt > output.txt

To remove a tab from the beginning of every line, run:

sed 's/^\t//g' input.txt > output.txt

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews