datafile has blank lines 
Author Message
 datafile has blank lines

All.

I am pretty new to writing shell scripts but have been getting on quite
well, or at least I like to think so. :-)

Currently I am writing a script that will automatically read in our software
configuration file (rat.cf) extract the database names from it and create a
new file containing these names. This contents of this file are then read in
later in the script as it runs an export of the database. At the moment the
script is as follows:

grep 2.4 /etc/rat/rat.cf > $LOGDIR/databases    #any line containing 2.4
(version no.) in the rat.cf send to the /export/logs/databases file
cut -d: -f9 databases > $LOGDIR/name.log    #read the databases file and cut
out database name, write this to the /export/logs/name.log file

server alias and write remaining to /export/logs/databases file

exec < databases    #read the database file
while read line    #for each line in the file
do
    cd $DUMPDIR    #change into /export/databases
    mkdir $line    #make a directory using the database name
    cd $line    #change into that directory
    /usr/informix/bin/dbexport $line    #run the export utility to backup
the database
    cd .. #change up one directory level
done

The problem is that the database file is written containing blank lines.
This is not a problem as the script still works but due to the blank lines
my logfile contains errors and being the perfectionist that I am I don't
like this. Can someone suggest a method that would delete the blank lines,
whenever I make an attempt at deleting lines I delete all of them. Not good
:-(

TIA

D.

--
__________
Darren Robertson
Technical Support
ORC Software
__________
Tel: +44 (0)20 7942 0999
Fax: +44 (0)20 7942 0940
www.orcsoftware.com
__________
Orc Software e-mail Disclaimer.
If you have received this e-mail in error or wish to read our e-mail
disclaimer statement and monitoring policy, please refer to
http://www.*-*-*.com/

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.*-*-*.com/ ).
Version: 6.0.325 / Virus Database: 182 - Release Date: 19/02/2002



Tue, 07 Sep 2004 00:43:41 GMT  
 datafile has blank lines

Quote:

>All.

>The problem is that the database file is written containing blank lines.
>This is not a problem as the script still works but due to the blank lines
>my logfile contains errors and being the perfectionist that I am I don't
>like this. Can someone suggest a method that would delete the blank lines,
>whenever I make an attempt at deleting lines I delete all of them. Not good
>:-(

grep . file > newfile
or
awk NF file > newfile
(the first one won't work if the blank lines contain spaces or tabs)


Tue, 07 Sep 2004 08:25:23 GMT  
 datafile has blank lines
I'm quite sure there a number of ways to skin this cat, but a real
simple solution would be to grep out blanks from the 'databases' file
in the last command line.

^ means beginning of line, $ means end of line, so ^$ means a line
with nothing between the beginning and end (think of them as my boss'
left and right ears).

See below.

Quote:

> grep 2.4 /etc/rat/rat.cf > $LOGDIR/databases
> cut -d: -f9 databases > $LOGDIR/name.


**CHANGE TO:

Quote:
> exec < databases  
> while read line    
> do
>     cd $DUMPDIR    
>     mkdir $line
>     cd $line
>     /usr/informix/bin/dbexport $line
>     cd ..
> done

> The problem is that the database file is written containing blank lines.
> This is not a problem as the script still works but due to the blank lines
> my logfile contains errors and being the perfectionist that I am I don't
> like this. Can someone suggest a method that would delete the blank lines,
> whenever I make an attempt at deleting lines I delete all of them. Not good
> :-(



Tue, 07 Sep 2004 10:45:02 GMT  
 datafile has blank lines
# Top of script...
(NF==0) { getline;}


Tue, 07 Sep 2004 23:37:01 GMT  
 datafile has blank lines

Quote:
> # Top of script...
> (NF==0) { getline;}

Bad idiom.

If the file ends with a newline followed by whitespace possibly ending with
a newline, all pattern-action pairs below this will also be processed. And
if there are consecutive blank lines, this doesn't filter out the 'even
numbered' ones. Example.

$ cat foobar
test

$ gawk 'NF == 0 { getline } { ++n } END { print n }' foobar
2
$

Correct results require NF == 0 { next }.

$ cat foobar
test

$ gawk 'NF == 0 { getline } { ++n } END { print n }' foobar
1
$



Wed, 08 Sep 2004 03:55:32 GMT  
 datafile has blank lines
Thanks everybody for your help. I have now been able to remove the blank
lines from my datafile and therefore remove some error messages from the
logfile.

Much appreciated for you help.

Thanks again.

D.

--
__________
Darren Robertson
Technical Support
ORC Software
__________
Tel: +44 (0)20 7942 0999
Fax: +44 (0)20 7942 0940
www.orcsoftware.com
__________
Orc Software e-mail Disclaimer.
If you have received this e-mail in error or wish to read our e-mail
disclaimer statement and monitoring policy, please refer to
http://www.orcsoftware.com/disclaimer or contact the sender.


Quote:
> All.

> I am pretty new to writing shell scripts but have been getting on quite
> well, or at least I like to think so. :-)

> Currently I am writing a script that will automatically read in our
software
> configuration file (rat.cf) extract the database names from it and create
a
> new file containing these names. This contents of this file are then read
in
> later in the script as it runs an export of the database. At the moment
the
> script is as follows:

> grep 2.4 /etc/rat/rat.cf > $LOGDIR/databases    #any line containing 2.4
> (version no.) in the rat.cf send to the /export/logs/databases file
> cut -d: -f9 databases > $LOGDIR/name.log    #read the databases file and
cut
> out database name, write this to the /export/logs/name.log file

> server alias and write remaining to /export/logs/databases file

> exec < databases    #read the database file
> while read line    #for each line in the file
> do
>     cd $DUMPDIR    #change into /export/databases
>     mkdir $line    #make a directory using the database name
>     cd $line    #change into that directory
>     /usr/informix/bin/dbexport $line    #run the export utility to backup
> the database
>     cd .. #change up one directory level
> done

> The problem is that the database file is written containing blank lines.
> This is not a problem as the script still works but due to the blank lines
> my logfile contains errors and being the perfectionist that I am I don't
> like this. Can someone suggest a method that would delete the blank lines,
> whenever I make an attempt at deleting lines I delete all of them. Not
good
> :-(

> TIA

> D.

> --
> __________
> Darren Robertson
> Technical Support
> ORC Software
> __________
> Tel: +44 (0)20 7942 0999
> Fax: +44 (0)20 7942 0940
> www.orcsoftware.com
> __________
> Orc Software e-mail Disclaimer.
> If you have received this e-mail in error or wish to read our e-mail
> disclaimer statement and monitoring policy, please refer to
> http://www.orcsoftware.com/disclaimer or contact the sender.

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.325 / Virus Database: 182 - Release Date: 19/02/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.325 / Virus Database: 182 - Release Date: 19/02/2002


Fri, 10 Sep 2004 17:59:27 GMT  
 
 [ 6 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. Blank lines

8. Removing data between blank lines

9. line beginning with a blank

10. blank lines

11. how to specify a blank line as record separator

12. Blank lines problems

 

 
Powered by phpBB® Forum Software