The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-27-2007
ghostdog74 ghostdog74 is offline
Registered User
 

Join Date: Sep 2006
Posts: 1,448
Code:
awk ' BEGIN{FS="= "} 
      /Condition/ {cond = $2 ; print $0    ;next}
      /^$/ { print cond ; next}
      {print $0 " " cond}
    ' "file"
output:
Code:
# ./test.sh
Condition = XXX
XXX
Header Line 1 XXX
Header Line 2 XXX
XXX
Station Data XXX
1 5.43 XXX
2 6.43 XXX
3 7.8 XXX
4 450 XXX
5 650 XXX
XXX
Condition = YYY
YYY
Header Line 1 YYY
Header Line 2 YYY
YYY
Station Data YYY
1 654 YYY
2 987 YYY
3 875 YYY
4 874 YYY
5 678 YYY
YYY
Condition= ZZZ
ZZZ ZZZ
Reply With Quote