grep and store

When i grep a file and store it in a file it is storing as a zero byte file any way to avoid that.....

Post your command. There is no way to give an accurate answer without that. Here is a thought though. Are you doing something like:

grep "something" arunkumar.txt > arunkumar.txt

This will truncate the file first and then run the grep on that file; which will obviously output a zero byte file.

Thank you but i want to do grep a same file and save in that file is that possible ?? please give some idea

grep pattern filename >> filename

this would append the pattern search into the filename,

is that you want?

Not with grep. However you could do it with sed if you are on a gnu system.

try this command

grep "expression" filename | & tee log

This work for all command , one output will redirected to standard output which is screen and another in the file name log.

rajesh

Two solutions ...

With sed (2 steps):

sed -n '/expression/p' filename > tempfile
mv tempfile filename

With perl (1 step) :

perl -n -i -e 'print if /expression/' filename

Jean-Pierre.