Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join two lines 1

Status
Not open for further replies.
Oct 10, 2003
2,323
0
36
US
similar to thread822-1378654, but my keyword is on the 2nd line.
Sample Data:
15 EL01-007-CUST-SAVACCT-1 REDEFINES EL01-EVENT-DATA.
20 EL01-007-FR-CUST-SAV1
PIC X(17).
20 EL01-007-TO-CUST-SAV1
PIC X(17).
20 FILLER PIC X(416).
15 EL01-008-CUST-VERID REDEFINES EL01-EVENT-DATA.
20 EL01-008-FR-CUST-VERID
PIC X(15).
20 EL01-008-TO-CUST-VERID
PIC X(15).
20 FILLER PIC X(420).

Problem: If a line starts with PIC, I want to join it to the previous line. However, if the PIC is not first (like the FILLER lines, do nothing. If no PIC in the line, do nothing. This file is 12k lines, so not practical to do manually.
Thanks for the help getting started.

==================================
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright


 


Try this:
Code:
awk '$1=="PIC"{print ll" "$0; next} substr($0,length($0),1)=="." {print $0;next}{ll=$0}' cobdata.txt
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
awk '/^PIC/{print x" "$0;next}{x=$0}/\.$/' sample_data

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top