Unix Scripting Question

Cupp Michael E Contr AFRL/DIB Michael.Cupp at wpafb.af.mil
Tue May 4 15:58:03 UTC 2004


Thanks Robert, but that says 2349 substitutions (# of lines in my file) - but I can <ESC> $ and end up 25 or so right spaces to the right of the closing quote - 

 

Breaking this down - it looks like % = entire file, s/ is search/replace \ $ means space before end of line //g means replace it with nothing and do it for every occurance of that line - seems logical to me - but doesn't seem to work. 

 

 

I have sent it to windows box - trying to do it in windows as we speak - maybe this will produce some luck.  (I know, I know - I'm sorry - but it's a production issue - I _HAVE_ to get this done - if I must resort to uncle bill's help, I will do so - ;)

 

 

M

-----Original Message-----
From: redhat-list-bounces at redhat.com [mailto:redhat-list-bounces at redhat.com] On Behalf Of Dege, Robert C.
Sent: Tuesday, May 04, 2004 11:50 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

 

In vi,

 

:%s/\ $//g

 

The $ represents the end of the line.

The ^ represents the beginning of the line.

 

-Rob

-----Original Message-----
From: Cupp Michael E Contr AFRL/DIB [mailto:Michael.Cupp at wpafb.af.mil]
Sent: Tuesday, May 04, 2004 11:43 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

The scipt was the command line shown below.

 

I have received a suggestion from Chris P. (THANKS, Chris) to use the perl script shown below - the problem is that my a.lst as used for input is formatted like this:

"/path/to/file/file name.doc"                                 

"/path/to/file/file name.doc"                                 

"/path/to/file/file name.doc"                                 

"/path/to/file/file name.doc"                                 

"/path/to/file/file name.doc"                                 

 

 

The problem with my a.lst is that after the closing ", there may or may not be trailing white space.  If there is, it's not allowing the match, and therefore the compare fails.

 

 

Any ideas how to get perl to ignore white space after the closing " or how I can strip this off the end.  (BUT NOT OUT OF THE MIDDLE - some of my file names in the a.lst are file ::SPACE:: ::SPACE:: :SPACE:: name.doc - or similar.

 

 

Thanks,

M

 

 

 

Chris' script here:

#!/usr/bin/perl

 

$a = '/export/home/oracle/a.lst';

open(FILE, $a) or die "Can't open file: $!\n";

@lines = <FILE>;

close FILE;

 

$exists = '/export/home/oracle/exists.txt';

open(EXISTS, ">$exists") or die "Couldn't open exists.txt for writing: $!\n";

 

$nonexist = '/export/home/oracle/nonexist.txt';

open(NONEXIST, ">$nonexist") or die "Couldn't open nonexists.txt for

writing: $!\n";

 

foreach (@lines) {

  $_ =~ s/"//g;

  chomp;

  if (-e $_) {

    print "$_ exists\n";

    print EXISTS "$_\n";

  } else {

    print "$_ doesn't exist\n";

    print NONEXIST "$_\n";

  }

}

 

close EXISTS;

close NONEXISTS;

 

 

-----Original Message-----
From: redhat-list-bounces at redhat.com [mailto:redhat-list-bounces at redhat.com] On Behalf Of Dege, Robert C.
Sent: Tuesday, May 04, 2004 11:34 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

 

Can you post your script?

-----Original Message-----
From: Cupp Michael E Contr AFRL/DIB [mailto:Michael.Cupp at wpafb.af.mil]
Sent: Tuesday, May 04, 2004 11:03 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

Still no luck - 

 

servername $for foo in `cat bb.lst` ^Jdo^Jecho $foo^Jdone

"/apps/htdocs/afrl/EBS/microsite/8583/COF\

Summary\

Apr03\

v2_2.ppt"

"/apps/htdocs/afrl/EBS/microsite/8583/Century\

of\

Flight\

\

Award\

-\

15Jan03_1.ppt"

servername $cat bb.lst

"/apps/htdocs/afrl/EBS/microsite/8583/COF\ Summary\ Apr03\ v2_2.ppt"

"/apps/htdocs/afrl/EBS/microsite/8583/Century\ of\ Flight\ \ Award\ -\ 15Jan03_1.ppt"

 

-----Original Message-----
From: redhat-list-bounces at redhat.com [mailto:redhat-list-bounces at redhat.com] On Behalf Of Dege, Robert C.
Sent: Tuesday, May 04, 2004 10:56 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

 

Using sed, you first need to escape the space, and then escape the back-slash.

 

(in vi)

 

:%s/\ /\\\ /g

 

-Rob

-----Original Message-----
From: Cupp Michael E Contr AFRL/DIB [mailto:Michael.Cupp at wpafb.af.mil]
Sent: Tuesday, May 04, 2004 10:51 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

How would I do that - :g/ /s/\ /g doesn't seem to work.

 

 

-----Original Message-----
From: redhat-list-bounces at redhat.com [mailto:redhat-list-bounces at redhat.com] On Behalf Of Dege, Robert C.
Sent: Tuesday, May 04, 2004 10:41 AM
To: 'General Red Hat Linux discussion list'
Subject: RE: Unix Scripting Question

 

Your problem could be that you need to escape the spaces in the file names prior to running your test.

 

Modify your a.lst file & replace all spaces ' ' with slash space '\ '

 

-Rob

-----Original Message-----
From: Cupp Michael E Contr AFRL/DIB [mailto:Michael.Cupp at wpafb.af.mil]
Sent: Tuesday, May 04, 2004 10:26 AM
To: 'redhat-list at redhat.com'
Subject: Unix Scripting Question

I have a file (a.lst) that has a list of fully pathed filenames, 1 per line - in this format:

"/path/to/the/name_of_file.doc"
"/path/to/the/other/name of the doc noting spaces.doc"

I need to know how I can loop through this file, a.lst, and for each entry, perform a test -s on it. If it exists, I want to put the entry into exists.txt, if it does not, I want to put the entry in noexist.txt -

Can someone please help me? (I've tried for foo in `cat a.lst`, but due to the spaces in 90% of the filenames, it pukes, as it appears to be using space as the delimiter)


Thanks again,
Michael 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/redhat-list/attachments/20040504/92c599d5/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 1063 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/redhat-list/attachments/20040504/92c599d5/attachment.gif>


More information about the redhat-list mailing list