Kaladin
Kaladin

Reputation: 11

Calling perl script within a bash "while" statement

I'd like help with calling a perl script from within the while loop of a bash script. An extract of my script is:

touch $OUTPUT_DIR/$OUTPUT_XML_PARSE

while read -r LINE; do
   perl newscript.pl "$LINE" >> $OUTPUT_DIR/$OUTPUT_XML_PARSE
done < $OUTPUT_DIR/$OUTPUT_FILENAME_LIST 

The file $OUTPUT_FILENAME_LIST contains a list of filenames each of which the Perl script uses as input argument to open and modify the data and writes the output to $OUTPUT_XML_PARSE.

The error when i run the program is "Can't open perl script "IDOCXML_parse.pl": A file or directory in the path name does not exist.". The perl script is in the same directory as the bash script, so I'm not sure why this is the case. Please advise.

Upvotes: 1

Views: 404

Answers (1)

glenn jackman
glenn jackman

Reputation: 246807

It sounds like you are invoking your script like /path/to/myscript.sh from some directory other than /path/to.

Try

perl "$(dirname "$0")/IDOCXML_parse.pl" ...

or

cd "$(dirname "$0")"
while read ...; do perl ./IDOCXML_parse.pl ...

Also, bash while-read loops are really slow. Try this

xargs -I X -L 1 perl ./IDOCXML_parse.pl X < input.file > output.file

or rewrite the perl script to accept the input file-of-filenames and let perl iterate over it.

Upvotes: 1

Related Questions