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

Clever Sed 1

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
Guys
I have a file ( sample below ) that should only have lines beginning with the date stamp. But the file sent has 4 lines per record. There's spurious newlines at pos 102, 188 and 264 that shouldn't be there.
How to remove 'em ????
The examples don't show too well on the display below though

01 JUN 02 B37171 31 6 +$0000000000000 +$0000000000000 +$0000000000000 +$0000
000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000020000 +$0000
000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000
000000000
01 JUN 02 B37271 21 7 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000020000 +$0000000000000 +$0000000000000 +$0000
000000000 +$0000000000000 +$0000000000000 +$0000000000000+$0000000000000 +$0000000000000 +$0000
000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000000000000 +$0000
000000000

should be :
01 JUN 02 B37171 31 6 +$0000000000000 +$0000000000000 +$0000000000000 +0 etc etc
01 JUN 02 B37271 21 7 +$0000000000000 +$0000000000000 +$0000000000000 +0 etc etc

TIA ;-)
Dickie Bird
db@dickiebird.freeserve.co.uk
 
If you just need to join every 4 lines into 1, try this awk script.
[tt]
{
printf $0
if (NR%4 == 0) print ""
}
[/tt] CaKiwi
 
With sed try out either:

a) If you can assume only the lines to print contain alphabetical characters as capitals.

sed '/[A-Z]/\!d'

b) Or just print every forth line starting with line 1.

sed 'N;N;N;s/\n.*//' Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
I may be misunderstanding this, but won't dos2unix or similar strip out the spurious newlines for you?
 
Thanks Guys
I didn't make it clear that I wanted to concatenate 4 lines into one record. Cakiwi's awk solution worked great.

Bigoldbulldog - I got this with your sed example :
cat 316*neg|sed '/[A-Z]/\!d' > db1.out
sed: 0602-403 /[A-Z]/\!d is not a recognized function.

All fixed anyway - Cheers [wavey] Dickie Bird
db@dickiebird.freeserve.co.uk
 
Whops,

That solution is supposed to be

sed '/[A-Z]/!d'

the \ before the ! is required for my version of c-smell command line. Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top