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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

records seperated by n lines

Status
Not open for further replies.

lenzand

MIS
Oct 29, 2007
3
US
Hi, please help
I need to re-layout a file so the records are on one line.
If I have 4 records then sample input:

10/29/2007
line 1 data
line 2 data
line 3 data
line 4 data
This line is rest of line 1
This line is rest of line 2
This line is rest of line 3
This line is rest of line 4

I need to put it like this:
10/29/2007 line 1 data This is rest of line 1
10/29/2007 line 3 data This is rest of line 2
10/29/2007 line 3 data This is rest of line 3
10/29/2007 line 4 data This is rest of line 4

so far I have:
NR == 1 { myday = $1
next
}
/^line/ {
firstpart[NR] = $0
}
/^this/ {


???
 
I think I have it but
Will this work for tens of thousands of records? (large input file)
plus I don't like that I have to use the string "line"...

NF > 0 {
records[NR] = $0
if ( NR == 1 ) gvmyday = $1
if ( $1 == "line" ) cnter+=1
}
END {
if (NR > 1) {
for ( i = 2; i <= (length(records)-cnter; ++i )
print gvmyday, records, records[i+cnter]
}
}
 
oops... input file is a little more complicated

===
10/29/2007
line 1 data
line 2 data
line n data
This is the rest of line 1
This is the rest of line 2
This is the rest of line n
new line 1 data
new line 2 data
new line n data
This is the rest of line 1 new data
This is the rest of line 2 new data
This is the rest of line n new data

desired output
10/29/2007 line 1 data This is the rest of line 1
10/29/2007 line 2 data This is the rest of line 2
10/29/2007 line n data This is the rest of line n
10/29/2007 new line 1 data This is the rest of line 1 new data
10/29/2007 new line 2 data This is the rest of line 2 new data
10/29/2007 new line n data This is the rest of line n new data



my script above will not do this...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top