Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Conditional newline removal via sed

Original Message
Name: dbtech
Date: April 18, 2006 at 17:12:24 Pacific
Subject: Conditional newline removal via sed
OS: RedHat Linux ES4
CPU/Ram: Xeon
Model/Manufacturer: Dell 2650
Comment:
I've been wrestling with sed for a while and have been unable to arrive the correct solution to the problem.

I have a file containing a large number of XML 'documents'. Most of them are contained on one line, but occassionally, some have embedded newlines. Using sed with the N to grab the next line isn't sufficient, since there may be more than two newlines. So, looking at the sample data below, the goal is to remove the newline for every line that does *not* end with the string </AUDIT>.

So... this data:
<AUDIT>all on one line</AUDIT>
<AUDIT>on two lines
this one is</AUDIT>
<AUDIT>of three lines, this it the first
this the second
and finally, the third</AUDIT>
<AUDIT>all on one again</AUDIT>
<AUDIT>this one
stretches across
a quite a few
lines
you never know how
many</AUDIT>
.
.
.
should end up looking like this:
<AUDIT>all on one line</AUDIT>
<AUDIT>on two lines this one is</AUDIT>
<AUDIT>of three lines, this it the first this the second and finally, the third</AUDIT>
<AUDIT>all on one again</AUDIT>
<AUDIT>this one stretches across a quite a few lines you never know how many</AUDIT>

TIA,

David



Report Offensive Message For Removal


Response Number 1
Name: lchi2000g
Date: April 19, 2006 at 07:54:56 Pacific
Subject: Conditional newline removal via sed
Reply: (edit)
Not a good way, but a simple way.

Run your program until wc -l returns the same value compared to the last run

Luke Chi


Report Offensive Follow Up For Removal

Response Number 2
Name: nails
Date: April 19, 2006 at 13:07:55 Pacific
Subject: Conditional newline removal via sed
Reply: (edit)
Take a look at this link:

http://main.rtfiber.com.tw/~changyj/sed/html/p.20020306a.html

It might do what you want.


Report Offensive Follow Up For Removal

Response Number 3
Name: dbtech
Date: April 19, 2006 at 14:16:14 Pacific
Subject: Conditional newline removal via sed
Reply: (edit)
Many thanks nails, that worked - I owe you a beer.

David


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: April 20, 2006 at 07:53:43 Pacific
Subject: Conditional newline removal via sed
Reply: (edit)
you are welcome.

Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Conditional newline removal via sed

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12

help mandriva install last straw!

Icon Scaling in Explorer Bar


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC