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!

Joining lines based on the beginning word.

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
Hi all,
I am trying to join words to their previous line based on a condition. If a line begins with a word that does not begin with "USAGE", then it should join to previous line. I am showing as example below. Please let me know if we can we do it with a script. Thanks for your help in advance.

Before:

USAGE100
abc
USAGE 101
def
USAGE 102 ghi jkl
USAGE 103
mno


After:


USAGE100 abc
USAGE.101 def
USAGE 102 ghi jkl
USAGE 103 mno
 
Here is one way:

Code:
awk '[green]/^USAGE/[/green] && [blue]NR[/blue]>1 { [b]print[/b] [red]"[/red][purple][/purple][red]"[/red] } { [b]printf[/b] [blue]$0[/blue][red]"[/red][purple] [/purple][red]"[/red] } [green]END[/green] { [b]print[/b] [red]"[/red][purple][/purple][red]"[/red] }' inputfile


Annihilannic.
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top