Remove text between two patterns

This can be done in UNIX by using SED For example: I want to remove the text between foo and bar

 

file.txt contains:

white

green

blue

foo

red

black

bar

yellow


sed '/foo/,/bar/{d;}' file.txt


Output:

white

green

blue

red

black

yellow

Hope this helps!!!
Read more ...

Find and Replace from Command Line

I had a situation where I had to find and replace in files with out creating new files and renaming them back, so after some research on Google I came up with this:


find . type –f | xargs perl –pi –e 's/foo/bar/g'

Read more ...

Find text in files using find

How to list all files having particular text in UNIX, you can do it by using find and grep
For example, if we want to list all files in present working directory containing foo, the following command helps

find . -type f | xargs grep foo

Instead of period you can give the directory location.

find /usr/home/akt -type f | xargs grep -i foo
-i for ignore case
Read more ...