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 -->
  #1 (permalink)  
Old 04-27-2007
selkirk selkirk is offline
Registered User
 

Join Date: Apr 2007
Posts: 4
Question SED or AWK: Appending a line Identifier that changes with paragraph?

Have another question that has been eluding me all day.

I have data file I'm trying to reformat so that each line is appended with an ID code, but the ID code needs to update as it searches through the file.

I.e.


----Begin Original Datafile-----
Condition = XXX

Header Line 1
Header Line 2

Station Data
1 5.43
2 6.43
3 7.8
4 450
5 650

Condition = YYY

Header Line 1
Header Line 2

Station Data
1 654
2 987
3 875
4 874
5 678

Condition= ZZZ
ZZZ
.
.
.
.
----------End Data File-----------


and I would like to convert it to


--------Begin Desired Datafile ------
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.80 XXX
4 4500 XXX
5 6506 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
.
.
.
------End Desired Datafile ------

With possibly several thousand unique Condition ID's and datasets. There are also some blank and header lines before each data set and appending the line identifier to those is just fine. All the blank and header lines are already being deleted at a later step.

If it were just a few cases I could hard code it, but having the condition ID update as it goes is beyond me at the moment.

Thanks in advance! So far you all have been extremely helpful and I'll definitely be back.
Cheers
Josh
Reply With Quote
Remove advertisements
!!
!! Forum Sponsor