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!

Delete a Specific Blank Line.... 1

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to delete specific blank line(s):

Here's a example of the data:

Pool Name 1
blank line <<<<<****** Delete this blank line
tape info
tape info
tape info
tape info
blank line
Pool Name 2
blank line <<<<<****** Delete this blank line
tape info
tape info
tape info
tape info
blank line
.
.
Pool Name X
blank line <<<<<****** Delete this blank line
tape info
tape info
tape info
tape info
blank line

I would like to delete just the blank line(s) after "Pool Name X" and leave the other blank lines alone

Thanks.................
 
with awk:
Code:
nawk '/^Pool Name/ {print;getline;next}1' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vlad, That was cool. Can I ask whats the significance of "1" there.

Thanx
 
Hey Vlad......

This worked .......

Now I'm going to see if I can use it in a for loop and do the same to all the Pool Names in the file


Thanks!
 
hmmm, vlad
what when:
Code:
Pool Name Z
tape info
or
       Pool Name Z
       tape info
is that '1', at the end of statement,not a typo ?
 
1 in the pattern section is a shorthand for {print}
ie, 1 always evaluate to true and the default action is to print the current line.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
jdespres,

You dont have to write a loop. The script by vlad works for all. It looks for "Pool Name" as text and then it dosent matter if it is "Pool Name Z" or "Pool Name z". And I definitely dont think 1 is a typo. I tried it without a one and it didnt work. I have put a question to vlad about that 1.
:)
 
try this one:

Code:
nawk '/Pool Name/ {print;getline;if ($0 ~ /^$/) next}1' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Absolutely Outstanding!

The following works:

/usr/xpg4/bin/awk '/pool/ {print;getline;next}1' cscnb01_tapes

I tried it without the "1".... and it just pulled out the Pool names...

Fantastic!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top