problem executing awk in shell "not found"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem executing awk in shell "not found"
# 1  
Old 11-08-2010
problem executing awk in shell "not found"

Hello,

The INPUT file a.txt contains this

Code:
a
a
a
b
b
b

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

Code:
./k.sh a.txt > newfile.txt

Code:
#!/usr/bin/sh

infile="$1"

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

I get this error message on the command line:

Code:
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.
# 2  
Old 11-08-2010
Hi.

This works for me. What OS and shell are you using?
# 3  
Old 11-08-2010
was told that we're using POSIX

I removed the > before the infile

when I do it like this it works:
Code:
#!/usr/bin/sh

infile="$1/$2"

awk '{print $0;}' $infile

# 4  
Old 11-08-2010
Quote:
Originally Posted by script_op2a
was told that we're using POSIX
Which is pretty much like being told you're flying in an airplane. Accurate yet uninformative. Smilie
# 5  
Old 11-08-2010
The difference between
Code:
awk '{print $0;}' $infile

and
Code:
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.
# 6  
Old 11-08-2010
Quote:
Originally Posted by scottn
The difference between
Code:
awk '{print $0;}' $infile

and
Code:
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


# 7  
Old 11-08-2010
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

2. Shell Programming and Scripting

In shell scripting found "\n-" and don't know what is it for

Working on UNIX shell scripting I found in env file the following export H1="\n- " echo "${H1} Waiting for dependencies of ${MONITOR_KEY} to be satisfied ..." >> ${LOG} What is in shell \n- The new line character? Thanks for contribution (2 Replies)
Discussion started by: digioleg54
2 Replies

3. Shell Programming and Scripting

Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help

Hi, I am on a Solaris8 machine If someone can help me with adjusting this awk 1 liner (turning it into a real awkscript) to get by this "event not found error" ...or Present Perl solution code that works for Perl5.8 in the csh shell ...that would be great. ****************** ... (3 Replies)
Discussion started by: andy b
3 Replies

4. Shell Programming and Scripting

"Command not found" doing a while loop in bash/shell

i=0 numberofproducts=${#urls} #gets number of entries in array called "urls" numberofproductsminusone=`expr $numberofproducts - 1` #-subtract by one while do wget ${urls} i=$(( $i + 1 )) sleep 10 done I'm getting an error ./scrape: line 22: [0: command not found that... (3 Replies)
Discussion started by: phpchick
3 Replies

5. Fedora

Problem Executing "lvcreate" Command

Hi everyone, I use Fedora 17. I used gparted to created a dev/sdb2 partition. I then used vgextend to extend the volume group. The output of vgdisplay shows the condition of my volume group: --- Volume group --- VG Name vg_data System ID Format ... (2 Replies)
Discussion started by: mojoman
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

when executing .sh script in telnet error "script not found"

Hi. i have written a wrapper script which inturn call the ftp child script in it. Now the problem is when i executing the same script in my script directory through putty it is getting executed successfully;where as through telnet i get an error "scripts not found" Can some one help me... ... (1 Reply)
Discussion started by: smiley
1 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question