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

Inserting blank lines 2

Status
Not open for further replies.
Apr 13, 2004
316
US
Using either sed or awk, if I have a file that contains:

Jul 23 08:23:45 saturn
Jul 23 08:24:45 saturn
Jul 23 08:23:46 neptune
Jul 23 08:21:47 mercury
Jul 23 08:23:45 venus
Jul 23 08:32:45 venus
Jul 23 08:33:45 pluto
Jul 23 08:23:45 jupiter
Jul 23 08:23:45 jupiter
Jul 23 08:23:45 jupiter

And I want to insert a blank line AFTER each new instance of a hostname:

Jul 23 08:23:45 saturn
Jul 23 08:24:45 saturn

Jul 23 08:23:46 neptune

Jul 23 08:21:47 mercury

Jul 23 08:23:45 venus
Jul 23 08:32:45 venus

Jul 23 08:33:45 pluto

Jul 23 08:23:45 jupiter
Jul 23 08:23:45 jupiter
Jul 23 08:23:45 jupiter


Thanks!!
 
Untested

{
if (hn!=$NF) {
if (NR > 1) print ""
hn = $NF
}
print
}

CaKiwi
 
Code:
inst != $NF { printf "\n"; inst=$NF}
1

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
<modesty>
great minds think alike!
</modesty>

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I aplogize that I made a mistake. There is text on the line after the hostname. Taking this into account, how would this change the awk syntax?

Thanks!
***********************************

Jul 23 08:23:45 saturn libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:24:45 saturn libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:23:46 neptune libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:21:47 mercury libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:23:45 venus libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:32:45 venus libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:33:45 pluto libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:23:45 jupiter libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:23:45 jupiter libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
Jul 23 08:23:45 jupiter libcsa: [ID 702911 user.error] c2admin: RPC: Program not registered
 
Still untested

{
if (hn!=$4) {
if (NR > 1) print ""
hn = $4
}
print
}

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top