I have two Perl scripts for text processing based on two different input files. I would like to have one shell script that runs based on conditions.

If (input file) matches word /extraction_reversed/ run perlscript1.pl otherwise run perlscript2.pl.

Shell script to compile in terminal:

sh run.sh inputfile > outputfile
  • Do you mean inputfile contains word? – Thor Jul 13 '12 at 20:36
  • yes inputfile contains word extraction_reversed – jack Jul 13 '12 at 20:42

You can do something like:

if grep extraction_reversed "$1"; then
  perlscript1.pl "$1"
  perlscript2.pl "$1"

"$1" will be replaced by the argument passed to the script (i.e. inputfile).

  • Yeah, but this requires the input file to be named inputfile and to reside in the current working dir. I think it should be passed as parameter (question also looks like it) and probably should be passed on to the perl scripts (which is not 100% clear in the question). – zpea Jul 13 '12 at 22:27
  • Oh, and welcome to U&L :) – zpea Jul 13 '12 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.