Linux / Unix: sed – How to replace text in multiple files?

Posted by Jiltin     Tags: 19 June, 2009    14,074 views    (5) Comment

sed – is useful to find and replace text in single multiple files. * Replacing foo with foo_bar in a single file. sed -i ’s/foo/foo_bar/g’ somefile.module o -i = tell sed to edit the file(s) o s = substitute the following text o foo = what you want to substitute o foo_bar = what you want to replace o g = global, match all occurrences in the line * Replacing foo with foo_bar in a multiple files. sed -i Read Full Article (Click here)...

Categories : Scripts Unix Tags :

Power of Linux / Unix – Sed – return previous line for pattern match

Posted by Jiltin     Tags: , , , 25 January, 2009    1,819 views    (2) Comment

This shows the power of Linux Bash script to “return previous line for pattern match” Need some idea on file processing, I have file like below, Processing al sources … …No value found : CHECK. Completed comparing all  sources. Comparing schedulers… Processing al targets … …No value found : From above I need to extract the line where “No value found” is available, which is simple, but I also wanna print the line before Read Full Article (Click here)...

Categories : Scripts Unix Tags : , , ,

How to add quotes to begin of the string in unix / linux bash or using shell?

Posted by Jiltin     Tags: , , , 24 December, 2008    1,705 views    (0) Comment

Just had an issue to add single quotes to first char of the flat file. I tried this below and it is working sed -e "s/^/\’/g" filename The file image before update 1,2,3,4,5,6,apple 1,2,3,4,5,6,apple 1,1,0,4,2,3,apple 1,3,3,3,3,4,apple 1,1,0,4,2,3,apple 1,3,3,3,3,4,apple 1,1,0,4,2,3,apple 1,3,3,3,3,4,apple 1,1,0,4,2,3,apple 1,3,3,3,3,4,apple 1,1,1,1,1,1,orange 1,2,3,1,1,1,orange It is turned exactly Read Full Article (Click here)...

Categories : Scripts Unix Tags : , , ,

Linux shell bulk edit using SED editor

Posted by Jiltin     Tags: , , 17 December, 2008    1,283 views    (1) Comment

Question: I generally use Perl for this ex. perl -e ’s/pattern/replace/g’ -p -i <filename> I did something like this.. find . -type f -exec perl -e ’s/pattern/replace/g’ -p -i {} \; I want to do this with “sed” but what I get is the output being printed on the screen.. I can do sed -e ’s/pattern/replace/g’ < input > output but in my case of “find”, i dont want to create a bunch of output files, rather the Read Full Article (Click here)...

Categories : Scripts Unix Tags : , ,

Super ONE-LINERS FOR SED

Posted by Jiltin     Tags: , , 22 September, 2008    662 views    (1) Comment

If you have any additional scripts to contribute or if you find errors in this document, please send e-mail to the compiler. Indicate the version of sed you used, the operating system it was compiled for, and the nature of the problem. FILE SPACING: # double space a file sed G # double space a file which already has blank lines in it. Output file # should contain no more than one blank line between lines of text. sed ‘/^$/d;G’ # triple space a file sed ‘G;G’ # Read Full Article (Click here)...

Categories : Scripts Unix Tags : , ,