Operating System - HP-UX
1745915 Members
4410 Online
108723 Solutions
New Discussion юеВ

Cut empty lines in a file

 
SOLVED
Go to solution
FOREST Michel
Frequent Advisor

Cut empty lines in a file

Hi, I would like cut all empty lines which are in a file. My file was obtain whith this command :
sar -u 1 10 |awk '{print $2,$3,$4,$5}' |grep -v % |grep -v 9000

which returns me

root@merone:/home/root> sar -u 1 10 |awk '{print $2,$3,$4,$5}' |grep -v % |grep -v 9000


1 0 0 99
0 0 0 100
0 0 1 99
1 0 4 95
0 0 0 100
0 0 0 100
0 0 0 100
0 0 0 100
0 0 0 100
0 0 0 100

0 0 0 99
root@merone:/home/root>

I would like cut the empty lines, to add the other line in a another file.

Thanks to help me, i'm not a developper ! ! !
A rookie in the HP Forum :)
7 REPLIES 7
Robin Wakefield
Honored Contributor

Re: Cut empty lines in a file

Hi,

If you just want to get rid of the empty lines, add another grep:

sar -u 1 10 |awk '{print $2,$3,$4,$5}' |grep -v % |grep -v 9000 | grep -v "^ *$"

or

sar -u 1 10 |awk '{print $2,$3,$4,$5}' |grep -v -e % -e 9000 -e "^ *$"

Hope this is what you mean.

Rgds, Robin
Justo Exposito
Esteemed Contributor

Re: Cut empty lines in a file

Hi Michel,

Try this:
sar -u 1 10 |awk '{print $2,$3,$4,$5}' |grep -v % |grep -v 9000 > popo
echo "/^$\n1,.-1 w tt1\n.+1,$ w tt2" | ed popo

Regards,

Justo.
Help is a Beatiful word
Ruediger Noack
Valued Contributor

Re: Cut empty lines in a file

or:

sar -u 1 10 |awk '{if ($2 -ge 0) print $2,$3,$4,$5}' > yourfile

Ruediger


Steven Sim Kok Leong
Honored Contributor
Solution

Re: Cut empty lines in a file

Hi,

Just pull some strings :-) Simply pipe your command through strings ie.

# sar -u 1 10 | awk '{print $2,$3,$4,$5}' | grep -v % | grep -v 9000 | strings

Hope this helps. Regards.

Steven Sim Kok Leong
FOREST Michel
Frequent Advisor

Re: Cut empty lines in a file

Thanks to all, for all ! ! ! !
A rookie in the HP Forum :)
David Totsch
Valued Contributor

Re: Cut empty lines in a file

You many want to update your regular expression that matches "blank lines".

^& matches a new-line
^ *& matches a line with zero
or more spaces

What else can be "white space"? For instance,
what about a line with a tab or two? You might
want to upgrade to an extended regular
expression that easily covers more "blank
lines":

^[[:space:]]*&

-dlt-
Bill Hassell
Honored Contributor

Re: Cut empty lines in a file

And yet another (albeit esoteric) technique:

cat file | /usr/bin/ssp | /usr/bin/rmnl

to remove all blank lines. Works well.


Bill Hassell, sysadmin