For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2004 > How to erase these additional blank lines?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to erase these additional blank lines?
Han JIANG

2004-03-30, 1:37 pm

Hi,
I am a newbie on unix. I met a strange problem here on Origin 2000.

I created a text data file which had 1,000 lines on my pc (Windows of
course) and upload it to my acoount on Origin.When I use vi to edit it on
Origin, I found there is a additional blank line between every 2 lines!
That makes my program cann't input this datafile.

Who know what happen here? And how can erase these additional blank lines?
Please don't say erase them line by line since I have 1000 lines there.

Thanks!


Paul Van Delst

2004-03-30, 1:37 pm

Han JIANG wrote:
> Hi,
> I am a newbie on unix. I met a strange problem here on Origin 2000.
>
> I created a text data file which had 1,000 lines on my pc (Windows of
> course) and upload it to my acoount on Origin.When I use vi to edit it on
> Origin, I found there is a additional blank line between every 2 lines!
> That makes my program cann't input this datafile.
>
> Who know what happen here? And how can erase these additional blank lines?
> Please don't say erase them line by line since I have 1000 lines there.


Have a lookee at:

http://www.iconv.com/dos2unix.htm
or
http://www.simtel.net/pub/pd/51438.html
or
http://linux.maruhn.com/sec/dos2unix.html
or
http://home.xnet.com/~efflandt/pub/dos2unix.pl
etc etc.

Google reported a crapload more hits.

Alternatively, your SGI may have the dos2unix and unix2dos utilities already installed.

cheers,

paulv

glen herrmannsfeldt

2004-03-30, 1:37 pm

Han JIANG wrote:

> Hi,
> I am a newbie on unix. I met a strange problem here on Origin 2000.
>
> I created a text data file which had 1,000 lines on my pc (Windows of
> course) and upload it to my acoount on Origin.When I use vi to edit it on
> Origin, I found there is a additional blank line between every 2 lines!
> That makes my program cann't input this datafile.
>
> Who know what happen here? And how can erase these additional blank lines?
> Please don't say erase them line by line since I have 1000 lines there.



On unix:

grep -v ^$ oldfile > newfile

will remove zero length lines. If they might have space or tabs
in them:

grep -v '^[[:space:]]*$' oldfile > newfile

-- glen

Han JIANG

2004-03-30, 1:37 pm

It works. Thanks a lot!

Han Jiang

"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:Jniac.136487$1p.1786747@attbi_s54...
> Han JIANG wrote:
>
on[color=darkred]
lines?[color=darkred]
>
>
> On unix:
>
> grep -v ^$ oldfile > newfile
>
> will remove zero length lines. If they might have space or tabs
> in them:
>
> grep -v '^[[:space:]]*$' oldfile > newfile
>
> -- glen
>



Richard Maine

2004-03-30, 2:39 pm

glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:

> On unix:
>
> grep -v ^$ oldfile > newfile
>
> will remove zero length lines. If they might have space or tabs
> in them:
>
> grep -v '^[[:space:]]*$' oldfile > newfile


Of course, that will remove *ALL* such lines, not just the ones
spuriously added by the data transfer. That could make the
resulting code pretty painful to read if the original made
use of blank lines as is often recommended. I sure wouldn't
want to read my own code after it had been abused like that;
I'd disclaim ownership.

I'd think it better to go after the underlying cause (for example
by using tools like the dos2unix that Paul mentioned).

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
glen herrmannsfeldt

2004-03-30, 5:45 pm

Richard Maine wrote:

> glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:


(snip)

[color=darkred]
> Of course, that will remove *ALL* such lines, not just the ones
> spuriously added by the data transfer. That could make the
> resulting code pretty painful to read if the original made
> use of blank lines as is often recommended. I sure wouldn't
> want to read my own code after it had been abused like that;
> I'd disclaim ownership.


> I'd think it better to go after the underlying cause (for example
> by using tools like the dos2unix that Paul mentioned).


Oops, I missed that one. Though I did say what it would
do, and it seems that I was lucky. Though grep is something
that unix programmers should know about, anyway.

Also, it seems that not all unix have dos2unix, though

tr -d "\015" < oldfile > newfile

should do it on those that don't.

-- glen




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com