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!

Replace New line Character 2

Status
Not open for further replies.

dbadmin

Programmer
Jan 3, 2003
147
US
Hi,

I need to remove the newline character for certain lines of a file. There is a word to be searched on these lines.

Ex: Input file

Network 10.1.028 2.2067 Placeholder
10.27.96
90.24.87
10.0.1
Network 10.2.028 2.2077 Placeholder
10.27.92
90.22.87
10.0.10

Output

Network 10.1.028 2.2067 Placeholder10.27.96
90.24.87
10.0.1
Network 10.2.028 2.2077 Placeholder10.27.92
90.22.87
10.0.10

I tried to remove the newline character using tr command and it makes a single line file (removes all newline characters). I need only to remove the new line character from the line with the Word "Network"

Any help is really appreciated.

Thanks in advance
dbadmin.

 
a way ....

Code:
#!/bin/ksh

awk ' { if($NF == "Placeholder")
           printf("%s ", $0)
        else
           printf("%s\n", $0)
} ' datafile
 
Using [tt]sed[/tt]...
Code:
sed '/^.*Placeholder.*$/N;s/\n */ /g' datafile


 
I usually google [google]sed oneliners[/google] for these type of problems...

HTH,

p5wizard
 
Hi Gurus,

You guys really rock. Thanks for the answers.

dbadmin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top