Showing posts with label sed. Show all posts
Showing posts with label sed. Show all posts

Friday, 22 April 2011

Remove empty lines from txt


$ sed '/^$/d' input.txt > output.txt

Replace a string with another string in all files


$ sed -i 's/old-word/new-word/g' *.txt

$ perl -pie 's/old-word/new-word/g' input > output

References
http://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/

Replace String in text file with sed


replace all occurances (g) of string 'old' with 'new' in file 'file' in place (i):

$ sed -i "s/old/new/g" file