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

No comments:

Post a Comment

About This Blog

KBlog logo This blog seeks to provide a collection of interesting pictures found on the Web. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

Powered By Blogger