Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
Just a friendly reminder to go work on your accept rate. If you aren't getting good answers to your questions, work on improving and clarifying them. If you do have an acceptable answer, mark it as such. –  jw013 Jul 13 '12 at 20:07
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
Hey jack! In order to motivate people to answer your question you might consider working on your accept rate (i.e. click accept for good answers to your old questions). Also, in your questions always tell us what you tried yourself. That lets us understand better where exactly you are stuck. –  zpea Jul 13 '12 at 22:23

1 Answer 1

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.