Message-ID: <3A3F280D.65FF82D5@turk.net> Date: Tue, 19 Dec 2000 11:19:09 +0200 From: Togan Muftuoglu <toganm@turk.net> Subject: Script help needed Hi everyone, Being a complete non script oriented person, I need help with script. This could be easy for many people on this list yet I am hopeless. This is want I want to do. I have plain text files ranging from 20K to 100K they all contain words. However there are blank lines in between the words. I want to automate the deletion of the blank lines how can I do this ? Could be a macrop with a wordprocessor also what ever will do the job is fine with me. The text files look like this word1 word2 word3 But after the conversion I want them to look like this word1 word2 word3 TIA -- Togan Muftuoglu toganm@turk.net 100% MS FREE Absolutely no component of Microsoft was used in the generation or posting of this e-mail. So it is virus free
Date: Tue, 19 Dec 2000 10:46:53 +0100 (CET) From: Mertz Denis <mertz@L2MP.u-3mrs.fr> Message-ID: <Pine.LNX.4.31.0012191041030.30772-100000@matop.u-3mrs.fr> Subject: Re: [SLE] Script help needed On Tue, 19 Dec 2000, Togan Muftuoglu wrote:
The text files look like this
word1
word2
word3
But after the conversion I want them to look like this
word1 word2 word3
This can be done with awk : gawk ' NF>=1 {print $0} ' file.in > file.out This works good for a file or two If you have many files to convert you need to write a little script but it depends on the file names that need to be converted -- Mertz Denis
Message-ID: <3A3F30E0.24539DCB@turk.net> Date: Tue, 19 Dec 2000 11:56:48 +0200 From: Togan Muftuoglu <toganm@turk.net> Subject: Re: [SLE] Script help needed Mertz Denis wrote:
This can be done with awk :
gawk ' NF>=1 {print $0} ' file.in > file.out
This works good for a file or two If you have many files to convert you need to write a little script but it depends on the file names that need to be converted
I am happy to do by hand for 28 files thanks a lot
-- Mertz Denis
-- Togan Muftuoglu toganm@turk.net 100% MS FREE Absolutely no component of Microsoft was used in the generation or posting of this e-mail. So it is virus free
Date: Tue, 19 Dec 2000 09:46:57 +0000 From: Tor Sigurdsson <tosi@suse.starf.rhi.hi.is> Message-ID: <20001219094657.A3262@dustpuppy.suse.starf.rhi.hi.is> Subject: Re: [SLE] Script help needed grep -v ^$ < testfile.txt > new_textfile.txt -tosi On Tue, Dec 19, 2000 at 11:19:09AM +0200, Togan Muftuoglu wrote:
Hi everyone,
Being a complete non script oriented person, I need help with script. This could be easy for many people on this list yet I am hopeless. This is want I want to do. I have plain text files ranging from 20K to 100K they all contain words. However there are blank lines in between the words. I want to automate the deletion of the blank lines how can I do this ? Could be a macrop with a wordprocessor also what ever will do the job is fine with me.
The text files look like this
word1
word2
word3
But after the conversion I want them to look like this
word1 word2 word3
TIA
-- Togan Muftuoglu toganm@turk.net
100% MS FREE Absolutely no component of Microsoft was used in the generation or posting of this e-mail. So it is virus free
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/support/faq
-- ______ /---------------------------------------\ \ | Þór Sigurðsson | Tor Sigurdsson | t | | Netmaður | Network Specialist | o | |-----------------------------------------| s | | tosi@rhi.hi.is | i | \---------------------------------------/_____/
From: "Koos Pol" <koos_pol@nl.compuware.com> Date: 19 Dec 2000 10:57:57 CET Message-Id: <20001219095800.B29B18293@bitbucket.extern.uniface.nl> Subject: Re: [SLE] Script help needed Here is a Perl script that will do the job. Remove the comment if you want to remove "empty" lines with spaces-only too. I have tested it and it works for my files. But no guarantees. Oh... the files are not backed up... So back'em up yourself first. Save this file as delemptylines.pl and invoke it like: perl delemptylines.pl file1 file2 file3 ... <p>while ($file = shift(@ARGV)) { print "Processing $file\n"; if ( ! open (F, "<$file")) { warn "Can't open $file for reading ($!)\n"; next; } undef $/; $_=<F>; close (F); # s/\n\s+\n/\n/g; # Removed "empty" lines with spaces-only. s/\n+/\n/g; if (! open (F,">$file")) { warn "Can't open $file for writing ($!)\n"; next; } print F $_; } <p>Cheers, -- Koos Pol ---------------------------------------------------------------------- S.C. Pol T: +31 20 3116122 Systems Administrator F: +31 20 3116200 Compuware Europe B.V. E: koos_pol@nl.compuware.com Amsterdam PGP public key available
Date: Tue, 19 Dec 2000 12:11:53 +0100 From: Stefan Troeger <stefan@troeger.st> Message-Id: <20001219121153.A2969@one.sttr.de> Subject: Re: [SLE] Script help needed Hi, On Tue, Dec 19 2000 at 11:19 +0200, Togan Muftuoglu wrote:
Being a complete non script oriented person, I need help with script. This could be easy for many people on this list yet I am hopeless. This is want I want to do. I have plain text files ranging from 20K to 100K they all contain words. However there are blank lines in between the words. I want to automate the deletion of the blank lines how can I do this ? Could be a macrop with a wordprocessor also what ever will do the job is fine with me.
Try perl -ne 'print unless /^\s*$/' -i~ * Ciao, Stefan
Message-ID: <3A3F62A3.BA3DDE5@asml.nl> Date: Tue, 19 Dec 2000 14:29:07 +0100 From: Martijn van den Burg <Martijn.van.den.Burg@asml.nl> Subject: Re: [SLE] Script help needed Hi, Stefan Troeger wrote:
Hi,
On Tue, Dec 19 2000 at 11:19 +0200, Togan Muftuoglu wrote:
Being a complete non script oriented person, I need help with script. This could be easy for many people on this list yet I am hopeless. This is want I want to do. I have plain text files ranging from 20K to 100K they all contain words. However there are blank lines in between the words. I want to automate the deletion of the blank lines how can I do this ? Could be a macrop with a wordprocessor also what ever will do the job is fine with me.
Try
perl -ne 'print unless /^\s*$/' -i~ *
Or: perl -ne 'print unless /^[\s|\t]*$/o' -i~ * ^^^^^^^ to skip lines which contain spaces and/or tabs. The 'o' adds a little more speed in case you have *big* files. By the way Stefan's neat one-liner saves the original files with a ~ behind them. <p>Bye, Martijn -- = Martijn van den Burg = Think globally = = Publications Department, ASML = Act locally = = Voice: +31 (0)40 268 3856 = = = Fax: +31 (0)40 268 2960 = =
Message-ID: <3A3F65CB.75363DD0@hursley.ibm.com> Date: Tue, 19 Dec 2000 13:42:35 +0000 From: Derek Fountain <fountai@hursley.ibm.com> Subject: Re: [SLE] Script help needed
perl -ne 'print unless /^\s*$/' -i~ *
Or:
perl -ne 'print unless /^[\s|\t]*$/o' -i~ *
^^^^^^^ to skip lines which contain spaces and/or tabs. The 'o' adds a little more speed in case you have *big* files.
\s matches [ \t\n\r\f] so that change is redundant. /o forces just one regex recompilation, which is exactly how many you get by default if the regex doesn't contain a variable interpolation (which this one doesn't). That change is redundant too.
From: Álvaro A. Novo <novo@uiuc.edu> Date: Tue, 19 Dec 2000 10:10:58 -0600 Message-Id: <0012191010580K.00483@friedman> Subject: Re: [SLE] Script help needed On Tuesday 19 December 2000 03:19, Togan Muftuoglu wrote:
The text files look like this
word1
word2
word3
But after the conversion I want them to look like this
word1 word2 word3
There's been several answers, but none using vi (or ex). In vi, I would do in command mode: :map t jddt Them place the cursor in the first line and press t
Date: Tue, 19 Dec 2000 12:22:03 -0500 (EST) From: "Christopher W. Aiken" <cwaiken@telerama.com> Message-ID: <Pine.LNX.4.21.0012191220130.2986-100000@darkstar.localdomain> Subject: Re: [SLE] Script help needed On Tue, 19 Dec 2000, Álvaro A. Novo wrote: ->On Tuesday 19 December 2000 03:19, Togan Muftuoglu wrote: -> > The text files look like this -> > -> > word1 -> > -> > word2 -> > -> > word3 -> > -> > But after the conversion I want them to look like this -> > -> > word1 -> > word2 -> > word3 -> ->There's been several answers, but none using vi (or ex). In vi, I would do in ->command mode: -> ->:map t jddt -> ->Them place the cursor in the first line and press t -> In "vi" you don't have to map any keys. Just do: :g/^$/d That's all.... <p> -- Christopher W. Aiken, Scenery Hill, Pa, USA chris at cwaiken dot com, www.cwaiken.com Current O/S: SuSE 7.0 Professional Linux
participants (9)
-
cwaiken@telerama.com
-
fountai@hursley.ibm.com
-
koos_pol@nl.compuware.com
-
Martijn.van.den.Burg@asml.nl
-
mertz@L2MP.u-3mrs.fr
-
novo@uiuc.edu
-
stefan@troeger.st
-
toganm@turk.net
-
tosi@suse.starf.rhi.hi.is