Results 1 to 5 of 5
Hey all,
I'm doing a grep on a bunch of files which always results in 2 lines that match. meaning that when i do :
grep "x" filename, the result ...
- 01-25-2008 #1Just Joined!
- Join Date
- Feb 2005
- Posts
- 37
Pretty basic Bash question
Hey all,
I'm doing a grep on a bunch of files which always results in 2 lines that match. meaning that when i do :
grep "x" filename, the result will always be
1: x byebye
2: x hello
How do I only grab the second results. I want to save "x hello" but not "x byebye" How can I do this? Thanks!
- 01-25-2008 #2
- 01-25-2008 #3Just Joined!
- Join Date
- Feb 2005
- Posts
- 37
Hi RobinVossen
Yes! I would be saving only the last result found in a variable. Thanks!
Jon
- 01-25-2008 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try this:
RegardsCode:awk '$1=="x"{f++} f==2{print;exit}' file
- 01-25-2008 #5Linux Newbie
- Join Date
- Nov 2007
- Location
- Planet Earth
- Posts
- 152
or just simply:
Code:myvar=`grep "x" your_file | tail -1`
EOF


Reply With Quote