pete
mary
joe
ron
Want file to look like:
bob
pete
mary
joe ron
I want to remove the blank line using a sed command but I can't seem to
get the right one. Any suggestions? Thanks.
Ken Magrow
If those lines are empty it's easy:
grep -v '^$' infile
If there might be white space, control characters etc., the more
general solution is:
grep "[!-~]" infile
If you really want to use sed:
sed '/^$/d' infile or
sed -n "/[!-~]/p" infile
The secret in either case is the regular expressions, "^$" matches
only empty lines; "[!-~]" matches any single character in the range.
A quick look at the ascii table (man ascii) will show you that this
will match everything in the standard table that is "printable".
For more on REs type "man ed".
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Cal Dunigan c...@ccdi.com There is something very wrong with
Consulting a world where Ken Thompson lives in
Modeling relative obscurity and Bill Gates
Training is a famous billionaire.
//////////////////////////////////////////////////////////////////////
>
> hello--
> I have a file say:
> bob
>
> pete
> mary
>
>
> joe
> ron
>
> Want file to look like:
>
> bob
> pete
> mary
> joe ron
>
> I want to remove the blank line using a sed command but I can't seem to
> get the right one. Any suggestions? Thanks.
sed -e "/^$/d"
or, to remove blank lines *and* lines containing no alphanumerical
characters:
sed -e "/^\W*$/d"
or, to remove blank lines *and* lines consisting only of spaces
sed -e "/^ *$/d"
--
-Neil Moore
(finger amet...@170.180.106.55 for my Geek Code/Nethack Code)
That's easy (once you know it ofcourse) :
sed '/$^/d' file
Harm
sed '/^$/d' file :-)
-Brian
--
,---. ,---. ,---. ,---. ,---. ,---. ,---.
/ _ \ / _ \ / _ \ / _ \ / _ \ / _ \ / _ \
.' / \ `.' / mailto:bsh2...@challenger.atc.fhda.edu \ `.' / \ `.
__,' `.___,' `.___,' `.___,' `.___,' `.___,' `.___,' `.__
On a tangential note, a useful idiom to learn is sort | uniq (or sort
-u, with many versions of sort). Then you often want to trash the
first line, tail +2 (with many versions of tail) or just grep -vx ''
to remove an empty line.
Hope this helps,
/* era */
> Want file to look like:
<...>
> joe ron
Let's just assume this was a typo? :-)
--
See <http://www.ling.helsinki.fi/~reriksso/> for mantra, disclaimer, etc.
* If you enjoy getting spam, I'd appreciate it if you'd register yourself
at the following URL: <http://www.ling.helsinki.fi/~reriksso/spam.html>
[...]
> I want to remove the blank line using a sed command but I can't
> seem to get the right one. Any suggestions? Thanks.
This is a non-sed solution:
grep . < INFILE > OUTFILE
Heiner
--
-------------------------------------------------------------
/ Heiner Steven h...@bintec.de / The expressed opinions are /
/ BinTec Communications / mine, not BinTec's -- /
/ Willstaetterstr. 30 ------- ...even if they should be ;-)/
/ D-90449 Nuernberg / http://www.bintec.de/english /
------------------------------------------------------------
WARNING: Untested theory:
use the sed command s/^ *$//
Just a thought...may not even be a well fromed one....
Joe Greene
No-one but me owns my opinions.
> I want to remove the blank line using a sed command but I can't
> seem to get the right one. Any suggestions? Thanks.
How about:
sed '/^$/d'
James
___________________________
mailto:Jame...@lucent.com
Try awk, thusly:
cat mess | awk 'NF!=0 {print}'
Should do the job. There's a variant on a theme with a counter in it, that
reduces it to 1 blank line at once (good for man pages).
~Tim
__________ ________________
_______/Tim Haynes\__________________________________/Top...@ed.ac.uk\_______
|Graduate CS-type person from Edinburgh http://www.tardis.ed.ac.uk/~tdxh |
|GCS d? p c++++ l= e* m* s--/+ !n h+ f+ !g w+ t--- r- y? |
| Just think.. to a worm, digging a hole deeper than he is long, is more |
| beneficial than going fishing. |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Kenneth A. Magrow (k-ma...@uiuc.edu) wrote:
> : I want to remove the blank line using a sed command but I can't seem to
> : get the right one. Any suggestions? Thanks.
>
> Try awk, thusly:
> cat mess | awk 'NF!=0 {print}'
I guess Randal Schwartz would prefer: awk 'NF!=0 {print}' mess
>
> Should do the job. There's a variant on a theme with a counter in it, that
> reduces it to 1 blank line at once (good for man pages).
>
> ~Tim
>
> __________ ________________
> _______/Tim Haynes\__________________________________/Top...@ed.ac.uk\_______
> |Graduate CS-type person from Edinburgh http://www.tardis.ed.ac.uk/~tdxh |> |GCS d? p c++++ l= e* m* s--/+ !n h+ f+ !g w+ t--- r- y? |> | Just think.. to a worm, digging a hole deeper than he is long, is more |> |
beneficial than going fishing. |> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>
>
I usually use: `sed -e '/^$/d' mess` to remove blank lines.
To remove "logically blank" lines, I might use:i
`sed -e '/^[ \t]*$/d' mess` if sed had a symbolic escape character
mechanism. Just replace "\t" by a tab character " "
--
Walter Briscoe
I would try using grep to pull all lines containing numbers OR alpha
chars thus leaving out blank lines, try this...
grep -E "[a-z]|[A-Z]|[0-9]" $filename
This uses a regular expression to say grep for all alpha chars in the
range of a thru z or zero thru 9; You could also try
grep -i -E "[a-z]|[0-9]" $filename
which should do the same (-i to ignore case, the square brackets denote
a range, and the pipe acts as OR).
Cheers
Randelld
--
## Note the above words of wisdom are mine, ##
## and not always those of my employer. ##
## Reply: rand...@fipltd.demon.co.uk ##
--
--------------------------------------------------------
You might be a redneck if you think I speak for NCR
--------------------------------------------------------
> Randell D. wrote:
> >
> > I would try using grep to pull all lines containing numbers OR alpha
> > chars thus leaving out blank lines, try this...
> >
> > grep -E "[a-z]|[A-Z]|[0-9]" $filename
> >
> > This uses a regular expression to say grep for all alpha chars in the
> > range of a thru z or zero thru 9; You could also try
> >
> > grep -i -E "[a-z]|[0-9]" $filename
> >
> > which should do the same (-i to ignore case, the square brackets denote
> > a range, and the pipe acts as OR).
> >
> > Cheers
> > Randelld
> > --Why not sed '/^[ ]*$/d', takes care of every semblance of
> blank line.
Well, yeah, unless there are non-printable characters.
grep "[!-~]" file
How about
grep . file
or
tr -s '\n' '\n' <file
--
dav...@davids.psyberlink.net |
Steinberger: | Bah Humbug
State of the Instrument |