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

Append next line

Status
Not open for further replies.

clemhoff

Technical User
Jul 10, 2007
19
FR
Hello,

I'm trying to append a line to previous if it doesn't begin with a equal sign

Input
...
=POUILLY SUR VINGEANNE
=2006
0628
59.9370-111
25.619
=45370
...

Expected Output:
...
=POUILLY SUR VINGEANNE
=2006|0628|59.9370-111|25.619
=45370

What I've tried so far:
Code:
awk '/^=/ {if (line) print line; line=""}{line = line $0"|"} END {if (line); print line }'

concatenation works but unfortunately I get a vertical bar on every line :eek:(

Can you please point my error ?!
Thank's in advance.

 
String concatenation is performed simply by juxtaposition.
Code:
# wrong
line = line $0"|"
# right
line = line $0
My way:
Code:
awk 'BEGIN{ORS=""} NR>1 && /^=/{print RS} 1 END{print RS}'
 
Thank you Futurelet for your answer

I tried your code, but I'm loosing the delimiter (vertical bar)
I get this
=2006062859.9370-11125.619

instead of:
=2006|0628|59.9370-111|25.619
 
you may try this:
Code:
awk '/^=/{if (line)print line;line=""}{line=line (line?"|":"")$0}END{if(line)print line}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, I definitively missed the logical condition... :(

Once again, thank you PHV for help, that works a treat.
 
Sorry. Overlooked that.
Code:
awk 'BEGIN{ORS=""} NR>1{print /^=/? RS:"|"}
 1 END{print RS}' myfile
 
No problem Futurelet !
Your proposal works too. Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top