to extract the lines in which serach and repl

May 4, 2011 at 20:53:13
Specs: Linux
$a=`tail -20 /var/log/messages`;
In $a i will search and replace some of the strings.
Now i wanted all those lines in which pattern hae been replaced.

please let me know how it can be accomplished

See More: to extract the lines in which serach and repl

Report •

May 4, 2011 at 22:06:08
First, to use command substitution in the bash shell, do not use a $ sign during the assignment:


a=`tail -20 /var/log/messages`

Second, I am not sure what you are trying to do as your requirements are vague, but it looks like you are going to need a 2-step process. I would send the output to a temp file instead of using a shell variable:

tail -20 /var/log/messages > tempfile.txt

Then, you can maybe use a combination of sed and grep to do what you want.

I like to use gres - global regular expression subsitution for string replacement purposes. It's discussed here:

You obviously have another requirement, but you are going to have to provide more information.

Report •
Related Solutions

Ask Question