Help: Perl Script Doesn't Write Out 
Author Message
 Help: Perl Script Doesn't Write Out

I have created a Bourne Shell script that is supposed to execute Perl
commands to change multiple dates within a file.  We found that we could
not use sed because it changes the number of bytes in the file, which
causes an out of synch situation with our program...Problem:

The script seems to never write out...What can I do to solve this
problem?  Here is the code in general:

#!/bin/sh

myname="/opt/jets/users/`whoami`/PNRForward"
if test -f $myname
then
        echo "$0: Cannot make directory $myname (already exists)" 1&>2
        exit 0
fi

echo "Enter the filename you want to age forward \c"
read FILENAME
mkdir "$myname"
echo "PNRForward is now in progress....go get a cup of coffee... \c"
perl -pe 's/18JUN/13aug/g'; \
-pe 's/19JUN/14aug/g'; \
-pe 's/20JUN/15aug/g'; \
-pe 's/21JUN/16aug/g'; \
-pe 's/22JUN/17aug/g'; \
-pe 's/23JUN/18aug/g'; \
-pe 's/24JUN/19aug/g'; \
$FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"
echo "done"

Thanks for any pointers.

A.



Sun, 05 Dec 2004 02:18:10 GMT  
 Help: Perl Script Doesn't Write Out

Quote:

> I have created a Bourne Shell script that is supposed to execute Perl
> commands to change multiple dates within a file.  We found that we could
> not use sed because it changes the number of bytes in the file, which
> causes an out of synch situation with our program...Problem:

> The script seems to never write out...What can I do to solve this
> problem?  Here is the code in general:

> #!/bin/sh

> myname="/opt/jets/users/`whoami`/PNRForward"
> if test -f $myname
> then
>         echo "$0: Cannot make directory $myname (already exists)" 1&>2
>         exit 0
> fi

> echo "Enter the filename you want to age forward \c"
> read FILENAME
> mkdir "$myname"
> echo "PNRForward is now in progress....go get a cup of coffee... \c"
> perl -pe 's/18JUN/13aug/g'; \

Hi,
the ';', placed outside '..', will be interpreted by the shell
but by perl, causing all the trouble, hence

  perl -pe 's/18JUN/13aug/g;' \
        -e 's/19JUN/14aug/g;' \
  ...
        -e 's/24JUN/19aug/g;' \
    $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

will work. BUT you should not ask for the prince when the
refuse collector can do the job :-) For such simple substitutions
there is the tiny 'sed' the right tool, try

  sed -e 's/18JUN/13aug/g' \
      -e 's/19JUN/14aug/g' \
  ...
      -e 's/24JUN/19aug/g' \
    $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

Tankred
---

- Show quoted text -

Quote:
> -pe 's/19JUN/14aug/g'; \
> -pe 's/20JUN/15aug/g'; \
> -pe 's/21JUN/16aug/g'; \
> -pe 's/22JUN/17aug/g'; \
> -pe 's/23JUN/18aug/g'; \
> -pe 's/24JUN/19aug/g'; \
> $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"
> echo "done"

> Thanks for any pointers.

> A.



Sun, 05 Dec 2004 19:26:39 GMT  
 Help: Perl Script Doesn't Write Out

Quote:

> I have created a Bourne Shell script that is supposed to execute Perl
> commands to change multiple dates within a file.  We found that we could
> not use sed because it changes the number of bytes in the file, which
> causes an out of synch situation with our program...Problem:

> The script seems to never write out...What can I do to solve this
> problem?  Here is the code in general:

> #!/bin/sh

> myname="/opt/jets/users/`whoami`/PNRForward"
> if test -f $myname
> then
>         echo "$0: Cannot make directory $myname (already exists)" 1&>2
>         exit 0
> fi

> echo "Enter the filename you want to age forward \c"
> read FILENAME
> mkdir "$myname"
> echo "PNRForward is now in progress....go get a cup of coffee... \c"
> perl -pe 's/18JUN/13aug/g'; \
> -pe 's/19JUN/14aug/g'; \
> -pe 's/20JUN/15aug/g'; \
> -pe 's/21JUN/16aug/g'; \
> -pe 's/22JUN/17aug/g'; \
> -pe 's/23JUN/18aug/g'; \
> -pe 's/24JUN/19aug/g'; \
> $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"
> echo "done"

> Thanks for any pointers.

> A.
> if test -f $myname

Firstly, you should be using '-d' as you are checking for the
existence of a directory.

I got the code to work by changing the perl call - removing all but
one of the '-pe' parameters and all but two of the single quotes.
The shell was interpreting the semi colons as a command separator (not
perl interpreting them, because they were outside the single quotes).
I ended up with:

perl -pe 's/18JUN/13aug/g; \
s/19JUN/14aug/g; \
s/20JUN/15aug/g; \
s/21JUN/16aug/g; \
s/22JUN/17aug/g; \
s/23JUN/18aug/g; \
s/24JUN/19aug/g;' \
$FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

Maybe you could simplify it with something like (this worked for me):
perl -pe 's/(\d\d)JUN/( $1 - 5 ). aug/eg;' ...

Damien.



Sun, 05 Dec 2004 21:02:34 GMT  
 Help: Perl Script Doesn't Write Out

Quote:

> #!/bin/sh

Your question is more about Bourne shell than it is about Perl.

Quote:
> perl -pe 's/18JUN/13aug/g'; \
> -pe 's/19JUN/14aug/g'; \
> $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

Semicolons are shell statement terminators so that's eqivalent to

perl -pe 's/18JUN/13aug/g'
-pe 's/19JUN/14aug/g'
$FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

That first statement reads from the parent script's STDIN.

When the end of STDIN is reached you'll get something like.

bash: -pe: command not found

I suspect you meant:

perl -pe 's/18JUN/13aug/g;
   s/19JUN/14aug/g' \
 $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

This newsgroup does not exist.  Please do not start threads here.  See FAQ.



Mon, 06 Dec 2004 00:16:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Image::Magick->Write() doesn't want to write

2. help!! perl script doesn't work

3. Help,Perl Script doesn't work!

4. HELP: Netscape 4.5 doesn't like text/html header from Perl script

5. help writing a perl script so that it's faster than sed

6. HELP: 'write' in perl 5.001 doesn't write "\n"

7. Apache, embperl, mod_perl : require doesn't work and can't write to file

8. Help the script doesn't work

9. Help -- script doesn't work through httpd

10. writing to db file fails even though the open doesn't

11. Why doesn't this script properly generate it's output

12. Mod perl script doesn't increment access log

 

 
Powered by phpBB® Forum Software