blank lines 
Author Message
 blank lines

Hello,

I have a plain text file separated by pipes but between some records
there is a blank line. How can I erase this blank line and join up the
records?

Ex.

1|2|3|4|5
1|2|2|4|6
          --> erase this line
1|2|3|4|5
1|2|3|4|5
1|2|2|4|6
         --> erase this line
1|2|3|4|5

Thanks in advance.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 10 May 2003 03:00:00 GMT  
 blank lines
awk '! /^$/'


Quote:

> Hello,

> I have a plain text file separated by pipes but between some records
> there is a blank line. How can I erase this blank line and join up the
> records?

> Ex.

> 1|2|3|4|5
> 1|2|2|4|6
>           --> erase this line
> 1|2|3|4|5
> 1|2|3|4|5
> 1|2|2|4|6
>          --> erase this line
> 1|2|3|4|5

> Thanks in advance.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 10 May 2003 03:00:00 GMT  
 blank lines

Quote:

> awk '! /^$/'

actually this way is better than mine so use this one!

--
Kev



Sat, 10 May 2003 03:00:00 GMT  
 blank lines

Quote:

> Hello,

> I have a plain text file separated by pipes but between some records
> there is a blank line. How can I erase this blank line and join up the
> records?

> Ex.

> 1|2|3|4|5
> 1|2|2|4|6
>           --> erase this line
> 1|2|3|4|5
> 1|2|3|4|5
> 1|2|2|4|6
>          --> erase this line
> 1|2|3|4|5

if every single line has a pipe in (except the blanks)
you could try this:

grep "|" file > newfile
mv newfile file

or

awk '$0 != ""' filename

Cheers,
--
Kev



Sat, 10 May 2003 03:00:00 GMT  
 blank lines

Quote:

> Hello,

> I have a plain text file separated by pipes but between some records
> there is a blank line. How can I erase this blank line and join up the
> records?

> Ex.

> 1|2|3|4|5
> 1|2|2|4|6
>           --> erase this line
> 1|2|3|4|5
> 1|2|3|4|5
> 1|2|2|4|6
>          --> erase this line
> 1|2|3|4|5

> Thanks in advance.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Another suggestion:

awk 'NF>0'

Does anyone know which of the suggested
methods is best?

Tristan.



Sat, 10 May 2003 03:00:00 GMT  
 blank lines


Quote:

...
>>I have a plain text file separated by pipes but between some records
>>there is a blank line. How can I erase this blank line and join up the
>>records?
...
>Another suggestion:

>awk 'NF>0'

>Does anyone know which of the suggested
>methods is best?

There's also

awk 'length' input_file > output_file

and yours could be shortened to just 'NF'.

Since '!/^$/' and 'length' involve additional parsing of each record,
'NF' would almost certainly take the least execution time, and it's
definitely tersest. Is that what you mean by best? However, '!/^$/' is
arguably clearest.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 10 May 2003 03:00:00 GMT  
 blank lines

Quote:


> > I have a plain text file separated by pipes but between some records
> > there is a blank line. How can I erase this blank line and join up the
> > records?

> > Ex.

> > 1|2|3|4|5
> > 1|2|2|4|6
> >           --> erase this line
> > 1|2|3|4|5
> > 1|2|3|4|5
> > 1|2|2|4|6
> >          --> erase this line
> > 1|2|3|4|5

> Another suggestion:

> awk 'NF>0'

> Does anyone know which of the suggested
> methods is best?

Regular expression pattern matching is overkill if the "blank"
lines are utterly devoid of text. In other words, this

    $0 != ""

is better than this

    $0 !~ /^$/

However, you might use a regular expression pattern if you wanted
to match what I call "blankish" lines:

    $0 !~ /^[ \t]*$/

But in the case where the value of FS is " ", then the simple
Boolean test NF will suffice for even "blankish" lines:

$ cat foobar
foo
bar

There is a single space on the next line

baz
$ awk NF foobar
foo
bar
There is a single space on the next line
baz
$

And if the only task is to remove blank lines, then using awk is
overkill. Use grep instead:

$ grep . foobar
foo
bar
There is a single space on the next line

baz
$ grep -v '^[   ]*$' foobar
foo
bar
There is a single space on the next line
baz
$

--
Jim Monty

Tempe, Arizona USA



Sat, 10 May 2003 03:00:00 GMT  
 blank lines

Quote:
> >awk 'NF>0'

> >Does anyone know which of the suggested
> >methods is best?

> There's also

> awk 'length' input_file > output_file

> and yours could be shortened to just 'NF'.

D'Oh. I should've spotted that!

Quote:
> Since '!/^$/' and 'length' involve additional parsing of each record,
> 'NF' would almost certainly take the least execution time, and it's
> definitely tersest. Is that what you mean by best?

I left that intentionally ambiguous to see what people's opinions
on the subject were. I guess it comes down to speed vs clarity
(again).

Quote:
> However, '!/^$/' is arguably clearest.

Agreed.

Thanks,

Tristan.



Sun, 11 May 2003 03:00:00 GMT  
 blank lines
Hi, everybody:

Quote:

> I have a plain text file separated by pipes but between some records
> there is a blank line. How can I erase this blank line and join up the
> records?

> Ex.

> 1|2|3|4|5
> 1|2|2|4|6
>           --> erase this line
> 1|2|3|4|5
> 1|2|3|4|5
> 1|2|2|4|6

I see you already had some good answers.
By the way, do you work with a 5ESS switch?

Greetings,
--
Fernando Fernandez Pedraza



Wed, 14 May 2003 10:29:44 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. remove blank lines before lines beginning with string

2. blank lines/lines with spaces (how to remove)

3. inserting a blank line in a file

4. to insert a blank line

5. adding blank lines to text file

6. print contents up to blank line

7. datafile has blank lines

8. Blank lines

9. Removing data between blank lines

10. how to specify a blank line as record separator

11. Blank lines problems

12. Using gawk to replace blank lines

 

 
Powered by phpBB® Forum Software