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!

SUB-criteria covering two lines ? 2

Status
Not open for further replies.

ChrB

Technical User
Feb 15, 2005
7
CH
Hi

I am new to AWK, on Windows, and need to re-format textfiles like this one:

:54:any text on one line
:86:this text field co
vers two lines or ev
en more lines
:54:here is another text on one line

The result should show all lines beginning with :xx: ; the
record starting with :86: should be on 1 line only:

:54:any text on one line
:86:this text field covers two lines or even more lines
:54:here is another text on one line

What would be the best way -
First removing all newlines and inserting newlines at the beginning of every :xx: ?
Or better, remove only these newlines which are not followed by :xx: ? But then, how do I do that ?

SUB seems not to be suitable when all newlines are removed - at least, I get no output.

What would you recommend?
 
awk '/^:[0-9][0-9]:/ && NR>1{printf "\n"}{printf "%s",$0}END{printf "\n"}' input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
/^:[0-9][0-9]:/ { printf "%s%s",line,line?RS:""
  line = "" }
{ line = line $0 }
END { print line }
Let me know whether or not this helps.

.

For an introduction to Awk, see faq271-5564.

 
Hi folks

Thanks a lot for your replies.
Both solutions are working fine!

Now I have to choose which one serves best.


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top