sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi,
I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :-

./sample.sh: line 13: sed: command not found
./sample.sh: line 15: awk: command not found

Can some one help me to figure out the problem.

Regards,
satish.

BASH is your shell, what is your system? uname -a if you don't know.

You may be having PATH problems if this is a UNIX system. Or if this is Windows via Cygwin or what have you, awk and sed may not be installed (they are applications, not part of bash)

Please post your script.

I cannot think of a more vague question then this....
Most likely providing the details of the script itself would be a good start...

Just a wild guess: use full paths when calling those commands in your script.

-bash-3.2$ unamae -a
Linux ukrliccprodems01 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22:44 EST 2010 x86_64 x86_64 x86_64 GNU/Linux

it is a unix system.

Regards,
satish

Great, that's one question answered, please answer my other by posting your script.

(Technically, Linux is not UNIX, but that's a bit legalistic.)

These are commands i gave :-

#!/bin/bash

sed -n '13,$'p /opt/sat/inp/sampledata.txt > /opt/sat/inp/sample2.txt

awk '{print $5}' /opt/sat/inp/sample2.txt > /opt/sat/inp/sample3.txt

regards,
satish

Try dos2unix sample.sh and test if error appear again.

Regards.

1 Like

-bash-3.2$ dos2unix sample.sh
dos2unix: converting file sample.sh to UNIX format ...

after running the above command still getting the same error while running my script

-----------------------

./sample.sh: line 13: sed: command not found
./sample.sh: line 15: awk: command not found
./sample.sh: line 16: -l: command not found

regards.

can you print the output of the below commands

which ack
which sed

And try to use the absolute path of awk and sed

Did you try something like this :

/usr/bin/awk 'NR>12{print $5}' /opt/sat/inp/sampledata.txt > /opt/sat/inp/sample3.txt

?

(Specifying the full path of your awk command wherever it is... make sure your user has relevant access rights).

as the first line of your script, echo "$PATH" and post its results please.

Also, could you do a copy/paste of the 17 first lines of your script in a code tags ?
I suspect an update to many variable (like PATH and/or IFS).

Regards.