[opensuse] question about awk
Guys, A question. I been trying to figure out how to get the out put I want. I got a log that I am do a grep on statement mykeyword, but I to get it and the line that follows. I been doing a search now for how to do this on google, but no luck. Is there a way of doing this, or do I need to use grep. -- ---------------------------------------- When a place gets crowded enough to require ID's, social collapse is not far away. It is time to go elsewhere. The best thing about space travel is that it made it possible to go elsewhere. -- Robert Heinlein -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday May 24 2009, Chuck Payne wrote:
Guys,
A question. I been trying to figure out how to get the out put I want. I got a log that I am do a grep on statement mykeyword, but I to get it and the line that follows. I been doing a search now for how to do this on google, but no luck. Is there a way of doing this, or do I need to use grep.
Sed suffices: % sed -n -e '/TargetPattern/,+1p' The sed default is simple REs. Extended REs (alternation, bounded closure, parens group by default) are available with the -r option. Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On May 24, 2009 06:01:10 pm Chuck Payne wrote:
A question. I been trying to figure out how to get the out put I want. I got a log that I am do a grep on statement mykeyword, but I to get it and the line that follows.
If I understand you correctly you want to get the line which contains your keyword and the line which follows. If so grep -A1 <mykeyword> <logfile> should work. You don't want to use grep? -- Don -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, 24 May 2009 20:01:10 -0400, Chuck Payne wrote:
A question. I been trying to figure out how to get the out put I want. I got a log that I am do a grep on statement mykeyword, but I to get it and the line that follows.
You can read the next line in awk and print it using "getline; print" Jim -- Jim Henderson Please keep on-topic replies on the list so everyone benefits -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 25 May 2009 02:01:10 Chuck Payne wrote:
Guys,
A question. I been trying to figure out how to get the out put I want. I got a log that I am do a grep on statement mykeyword, but I to get it and the line that follows. I been doing a search now for how to do this on google, but no luck. Is there a way of doing this, or do I need to use grep.
If I parse your question correctly, what you're looking for is grep -A 1 mykeyword logfile An awk hack (I'm not very fluent in awk-ish): { while ($0 ~ /foo/) { print; i=getline; } if (i > 0){ print; print "---------"; i=0; } } Just use grep Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, May 24, 2009 at 9:11 PM, Anders Johansson
On Monday 25 May 2009 02:01:10 Chuck Payne wrote:
Guys,
A question. I been trying to figure out how to get the out put I want. I got a log that I am do a grep on statement mykeyword, but I to get it and the line that follows. I been doing a search now for how to do this on google, but no luck. Is there a way of doing this, or do I need to use grep.
If I parse your question correctly, what you're looking for is
grep -A 1 mykeyword logfile
An awk hack (I'm not very fluent in awk-ish):
{ while ($0 ~ /foo/) { print; i=getline; } if (i > 0){ print; print "---------"; i=0; } }
Just use grep
Anders
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Guys thanks a lot, it looks like grep is the easy way to do what I want. Again thanks. -- ---------------------------------------- When a place gets crowded enough to require ID's, social collapse is not far away. It is time to go elsewhere. The best thing about space travel is that it made it possible to go elsewhere. -- Robert Heinlein -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Anders Johansson
-
Chuck Payne
-
Don Raboud
-
Jim Henderson
-
Randall R Schulz