sed issues

Hi guys, not that used to using sed beyond the simple substitution. I am trying to check for a program (program1) and if it exists replace the standard output "program1" with a "program1(part1 part2) output if said program exists.

SW="program1 program2"
PROGRAM_TEST='echo "$SW" | grep "program1"'
if test ! "$PROGRAM_TEST" = "" ;then
     PROGRAM1_LIST="part1 part2"
     sed -e 's/program1/program1($PROGRAM1_LIST)/g' $SW > $SW2
fi
if test "$SW2" = ""; then
     echo "software: $SW"
     else
     echo "software: $SW2"
fi

I believe the problem is to do with the sed substitution as the error given is:

sed: Cannot find or open file program1
sed: Cannot find or open file program2 

Any help or ideas on getting this to work?

$
$ echo "program1 program2" | grep "program1" 1>/dev/null && echo "program1(part1 part2)"
program1(part1 part2)
$
$ echo "program3 program2" | grep "program1" 1>/dev/null && echo "program1(part1 part2)"
$
$

tyler_durden

Thanks. worked it into a fix :slight_smile:

You haven't checked whether program1 or program2 exists. All you have done is check whether they are part of the string $SW (for which you don't need grep).