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!

urgent! Have file with lines. Need appending

Status
Not open for further replies.

lroldan

Technical User
Nov 1, 2001
1
CA
I have a file with 200,000 lines with information:

Server;
Date;
Event;
Source;
Sub_Source;
END;
Server;
Date;
Event;
Source;
Sub_Source;
Info;
END;

I need the output to look like the following:
Server;Date;Event;Source;Sub_Source;
Server;Date;Event;Source;Sub_Source;Info;

I appreciate any help. Thanks.
 
Hi lroldan,

This should do what you want.

{
if ($0 ~ /^END;/)
print ""
else
printf("%s",$0)
}

Hope this helps.
CaKiwi
 
good solution.

I've been trying to do similar, but with FS="^END;$"

CaKiwi, wanna take a stab at THAT approach?

vlad
 
Hi vgersh99,

As I see it, setting FS="^END;$" means that the END line will have 2 fields and the other lines will only have 1 field. So the following program should work.

BEGIN{FS="^END;$"}
{
if (FS==2)
print ""
else
printf("%s",$0)
}

Do you have any other thoughts on this?



CaKiwi
 
CaKiwi,

you ALMOST got it ;) A minor mistype.

vlad

BEGIN{
FS="^END;$"
}

{
if (NF >= 2)
print ""
else
printf $0
}
 
Oh well, I was close. I didn't know that the format string for the printf statement was optional, so that's something new I learnt today. CaKiwi
 

I was actually refering to "if (NF >= 2)" conditional - you've confused/mistyped FS with NF. Other than that - it's flawless ;)

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top