problem executing awk in shell "not found"

Hello,

The INPUT file a.txt contains this

a
a
a
b
b
b

I'm trying to execute this shell script from the Unix Command Line like this:

./k.sh a.txt > newfile.txt
#!/usr/bin/sh

infile="$1"

awk '{print $0;}' < $infile 

I get this error message on the command line:

Usage: awk [-F fs][-v Assignment][-f Progfile|Program][Assignment|File] ...
./k.sh[6]: {print $0;}:  not found.

I don't think I'm using awk properly can somebody help me?

I just want to print the contents of the infile to an outfile specified on the command line except using shell parameter.

Hi.

This works for me. What OS and shell are you using?

was told that we're using POSIX

I removed the > before the infile

when I do it like this it works:

#!/usr/bin/sh

infile="$1/$2"

awk '{print $0;}' $infile 

Which is pretty much like being told you're flying in an airplane. Accurate yet uninformative. :wink:

The difference between

awk '{print $0;}' $infile

and

awk '{print $0;}' < $infile

is whether to open a file for reading ($input) or reading from an existing file (standard input).

Unless you're keen to know the name of the file you're reading for, there's no real difference in this case.

As for "POSIX", when asked what OS you are using, it's neither here nor there.

I was told that it's POSIX, similar to the Korn shell. That you could use:

#!/usr/bin/sh
or
#!/usr/bin/ksh

in the shell scripts but they seem to work differenly so I'm sticking to /sh

POSIX has nothing to do with KSH.

KSH may be POSIX compliant, but that's neither here nor there.

The only system I know of where sh is really sh (as in Bourne Shell) is Solaris.

On AIX sh means KSH, on Linux it means bash or dash typically.

And none of this has anything to do with awk.

That just means they didn't tell you anything about what system you're actually using. There's no OS called "POSIX". POSIX is a paper standard which many wildly differing systems adhere to, to a greater or lesser degree.

Try uname

uname returns HP-UX

what do you think of that?

I was told we use the Korne shell but when I try to use the ksh path for shell scripts I get the little heart character appear on the line and it acts differently

so i use the sh path

You're talking to an HP-UX server, then, something I've never used. In many more traditional UNIX systems like Solaris and (I think) HP-UX, plain sh is a very different shell from ksh, you get an old-fashioned and extremely barebones Bourne shell. But we have a subforum just for HP-UX, you'll find folks there who can explain this behavior better than I could.