Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to shell script. 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
share|improve this question
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
up vote 3 down vote accepted

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).

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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