LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   sed (https://www.linuxquestions.org/questions/linux-general-1/sed-567244/)

sycamorex 07-06-2007 05:08 PM

sed
 
Hi all

I'm trying to achieve the following:

Code:

echo "Enter the word: "
read a

sed -n '$a p' file

Obviously, it doesn't bring the needed results. How can I accomplish
it in sed (is sed the best tool for it)?

Basically, I have large text files, and would like to search for
particular worlds in them. Ideally providing the context as well (previous and next lines as well)

Any help would be appreciated.
thank you

unSpawn 07-06-2007 05:16 PM

grep with the -A and -B args?

sycamorex 07-06-2007 05:24 PM

thanks, that's what I needed:)

Tinkster 07-06-2007 07:18 PM

Or, if you're lazy enough, -C :}
So, instead of e.g.
"grep -A 3 -B 3 word file"
just a
"grep -C 6 word file"

;}


Cheers,
Tink


All times are GMT -5. The time now is 05:38 PM.