By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,612 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,612 IT Pros & Developers. It's quick & easy.

awk/sed/bash to process multiline output

P: 1
Trying to process this output:

--------------snip---------------------
Change 123 by john

foo=bar
x=y
t=111

Change 456 by jim

foo=bar2
x=6

Change 789 by larry

foo=baz
hoo=hoo
t=222
--------------snip---------------------

Into something like this:

123 john 111
456 jim
789 larry 222



Any thoughts? awk, sed or bash will do.
Nov 3 '07 #1
Share this Question
Share on Google+
1 Reply

radoulov
P: 34
Expand|Select|Wrap|Line Numbers
  1. awk '/^Change/ {
  2.           printf r || f ? ($2 " " $4 " ") : ("\n" $2 " " $4 " ")
  3.           f = 0
  4.           r = 0
  5.     }
  6. /^t=/ { 
  7.           print $2
  8.           f = 1
  9.     }
  10. END {
  11.           if (! f) 
  12.         print ""
  13. }' FS="[= ]" r=1 filename
Use nawk or /usr/xpg4/bin/awk on Solaris.
Nov 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.