Unix Shell - Wildcard comparrison question

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > Wildcard comparrison question





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 Wildcard comparrison question
sjday66@hotmail.com

2007-02-26, 1:18 pm

Hi

I have a quick question that has stumped me. I want to report on files
that I have on the system. When it finds files with the name
containing SNL I want to perform report the information invalid and
stop processing that file, for all other files I want to run a awk
command that will extract certain information and report the outcome.

Now I am able to perform these commands separtly but I am unable to
get them to work together sucessfully.

An example of my code is as follows

ls -rt /*.ok /*.err|while read fname
do

# Output the file contents and look for the XML tag to identify the
start positi
on (Stored in RSTART)
# Next we look for the end tag and calculate the total length of our
contents an
d print the result
# if we find anything. If we don't then that search line will not get
printed.

echo $fname | awk '!/\.SNL/ { notsent = "|||||||"$1"||not sent|";
print notsent
}'

# The following doesn't work hence the question
<<<<<<<<<<<<<<<<<<<<<<<<
if [ "$notsent" = "true" ]
then
echo "|||||||$fname||not sent|"
else
cat $fname|awk ' function extract(extractSrc,extractPattern) {
if (match(extractSrc, "<"extractPattern">"))

.......


As you can see the first awk statement uses output from echo file the
second uses output from cat.

Many thanks in advance

Barry Margolin

2007-02-27, 1:24 am

In article <1172497491.789101.160910@p10g2000cwp.googlegroups.com>,
sjday66@hotmail.com wrote:

> Hi
>
> I have a quick question that has stumped me. I want to report on files
> that I have on the system. When it finds files with the name
> containing SNL I want to perform report the information invalid and
> stop processing that file, for all other files I want to run a awk
> command that will extract certain information and report the outcome.
>
> Now I am able to perform these commands separtly but I am unable to
> get them to work together sucessfully.
>
> An example of my code is as follows
>
> ls -rt /*.ok /*.err|while read fname
> do
>
> # Output the file contents and look for the XML tag to identify the
> start positi
> on (Stored in RSTART)
> # Next we look for the end tag and calculate the total length of our
> contents an
> d print the result
> # if we find anything. If we don't then that search line will not get
> printed.
>
> echo $fname | awk '!/\.SNL/ { notsent = "|||||||"$1"||not sent|";
> print notsent
> }'
>
> # The following doesn't work hence the question
> <<<<<<<<<<<<<<<<<<<<<<<<
> if [ "$notsent" = "true" ]


You never set the shell variable $notsent. You assigned to an awk
variable, not a shell variable. If you want to capture that in the
shell, you need to do something like:

notsent=`echo $FNAME | awk ...`

Although awk seems like way overkill for this, why not:

case "$fname" in
*.SNL*) notsent=true ;;
*) notsent=false ;;
esac

> then
> echo "|||||||$fname||not sent|"
> else
> cat $fname|awk ' function extract(extractSrc,extractPattern) {
> if (match(extractSrc, "<"extractPattern">"))
>
> ......
>
>
> As you can see the first awk statement uses output from echo file the
> second uses output from cat.


The problem is that $fname just contains the file name, not the complete
pathname. E.g. if the file is /foo.ok/file.SNL, you'll do "cat
file.SNL" instead of "cat /foo.ok/file.SNL". Run "ls -rt /*.ok" and
look at the output to see why.

Try changing your ls command to:

ls -rt /*.ok/* /*.err/* | while read fname

And if you do this you

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
sjday66@hotmail.com

2007-02-27, 7:21 am

Hi Barry

thanks for that it worked a charm

Stephen

Barry Margolin wrote:

> In article <1172497491.789101.160910@p10g2000cwp.googlegroups.com>,
> sjday66@hotmail.com wrote:
>
>
> You never set the shell variable $notsent. You assigned to an awk
> variable, not a shell variable. If you want to capture that in the
> shell, you need to do something like:
>
> notsent=`echo $FNAME | awk ...`
>
> Although awk seems like way overkill for this, why not:
>
> case "$fname" in
> *.SNL*) notsent=true ;;
> *) notsent=false ;;
> esac
>
>
> The problem is that $fname just contains the file name, not the complete
> pathname. E.g. if the file is /foo.ok/file.SNL, you'll do "cat
> file.SNL" instead of "cat /foo.ok/file.SNL". Run "ls -rt /*.ok" and
> look at the output to see why.
>
> Try changing your ls command to:
>
> ls -rt /*.ok/* /*.err/* | while read fname
>
> And if you do this you
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com