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

Replace a string including a newline character 1

Status
Not open for further replies.

neuralnode

Technical User
Sep 12, 2007
59
PL
Hi All,

Here's the task:

The contents of a text file is like this:

Code:
this is a string
55 and some other text

I want to replace every occurence of a newline character and the string "55".
So whenever there is "55" starting a line, the preceding newline character should be replaced with a space.

How can I do that?
(with some regex in perl/sed/awk)

Thanx in advance!
 
One way with awk:
awk 'NR>1{if($1~/^55/)printf " ";else printf "\n"}{printf "%s",$0}END{printf "\n"}' /path/to/input

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

Part and Inventory Search

Sponsor

Back
Top