Unix Scripting Question

Pete Nesbitt pete at linux1.ca
Wed May 5 02:24:17 UTC 2004


On May 4, 2004 08:42 am, Cupp Michael E Contr AFRL/DIB wrote:
> 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
>

Hi,

This works as a bash script or at the command line.

If you don't care about the quotes around the names, this will remove the 
trailing whitespace on each line, plus removes the empty lines:
egrep -v "^$" a.lst | awk -F\" '{print $2}'

if you want the quotes, this puts them back:
egrep -v "^$" test.lst|awk -F\" '{print $2}'|sed -e s/^/\"/|sed -e s/$/\"/

-- 
Pete Nesbitt, rhce





More information about the redhat-list mailing list