Awk: cannot open file (No such file or directory)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk: cannot open file (No such file or directory)
# 1  
Old 11-12-2012
Awk: cannot open file (No such file or directory)

Hello folks!
I am new to Shell and awk scripting.

This is my shell script that receives a string as an input from the user from the stdin.

Code:
#!bin/sh
printf "Enter your query\n"

read query
cmd=`echo $query | cut -f 1 -d " "`
input_file=`echo $query | cut -f 2 -d " "`
printf $input_file

if [ $input_file = "" ]
then
    printf "No input file specified\n"
    exit
fi
if [ $cmd = "summary" ]
then
    awk -f summary.awk $input_file $query
fi

Lets say he enters
Code:
summary a.txt some_other_options

Now "cmd" variable will take the value "summary" and "input_file" will take "a.txt".
Isn't that right?

I want summary.awk to work on $input_file, based on what is present in $query.
Isn't my approach right?

But when I run the shell script,
I get "awk: cannot open summary (No such file or directory)
"
I never intended to pass "summary" as my input file.
But it is the 1st word of $query. Is it getting perceived as the input file?
Why so?

My understanding is as follows :
1. The 1st command line argument passed is treated as input file.
e.g. : awk 'code' file arg1 arg2 arg3
only file is treated as input file

2. If the input file is piped, it doesn't see any of the arguments as input files.
e.g. : cat file | awk 'code' arg1 arg2 arg3
arg1 is NOT treated as input file.

Am I right?
Can you please help me?

Last edited by radiohead_; 11-12-2012 at 06:39 AM..
# 2  
Old 11-12-2012
Can you post the input file.. Try with nawk..

---------- Post updated at 04:45 AM ---------- Previous update was at 04:43 AM ----------

Added the path_name in the script
# 3  
Old 11-12-2012
It gives the error even if the input file is :
Code:
{print}

---------- Post updated at 03:25 PM ---------- Previous update was at 03:24 PM ----------

The same error with nawk

---------- Post updated at 03:27 PM ---------- Previous update was at 03:25 PM ----------

And, are those 2 points I mentioned, right?
# 4  
Old 11-12-2012
try:
Code:
#!/bin/sh
printf "Enter your query\n"

read cmd input_file

if [ $input_file = "" ]
then
    printf "No input file specified\n"
    exit
fi
if [ $cmd = "summary" ]
then
    awk -f summary.awk $input_file
fi

# 5  
Old 11-12-2012
But my query doesn't consist just of 2 words :cmd and input_file
Typically, it might look like this :
Code:
summary file /o output_file /t something

# 6  
Old 11-12-2012
First argument will be loaded into "cmd", the rest into "input_file".
# 7  
Old 11-12-2012
[Update]
I just tried it.
It essentially gives the same error, only now it is "/o" as input file that is finds non-existent.

Code:
 summary file /o output_file /t something

This was again used as input.

Last edited by radiohead_; 11-12-2012 at 06:29 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux open failed: No such file or directory error

Hi, The below commands works fine on serverB . /etc/profile; cd /export/home/user2/utils/plugin/ ./runme.shHowever, when i run the same commands from serverA it fails $ ssh -q user2@serverB ". /etc/profile; cd /export/home/user2/utils/plugin; ./runme.sh"Output Error: Please find the below... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

awk can't open file; file merge attempt

Dear all, I have an AWK related issue. I have two data files; the first, FileA has fewer lines, the second, FileB has more. FileA is a subset of FileB . Both files are tab delimited. What I want to do? When the first two columns for FileA match the first two columns of FileB, I want to... (4 Replies)
Discussion started by: A_Human_Person
4 Replies

3. Linux

Cannot open shared object file: No such file or directory

Hi, While running tcpdump command on my Fedora 16 machine I am get shared library issue. # tcpdump tcpdump: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory # which tcpdump /usr/software/sbin/tcpdump I have tried... (3 Replies)
Discussion started by: muzaffar.k
3 Replies

4. Solaris

./curl -V showing fatal: libldap.so.5: open failed: No such file or directory

Hi Guys, I am facing this Error bash-2.03$ ./curl -V ld.so.1: curl: fatal: libldap.so.5: open failed: No such file or directory Killed bash-2.03$ while executing ./curl -V in /opt/sfw/bin directory. I am using Sun Solaris 10. which package upgrage can give me this missing... (9 Replies)
Discussion started by: manalisharmabe
9 Replies

5. Shell Programming and Scripting

Cannot open [No such file or directory]

I am seeking help on one script that I created to celan up database audit files. The error returned is $./clean_audit.sh: /opt/oracle/logs/audit_clean.log: cannot open The same script is working on other 2 or 3 servers. But not working on other 4 servers. All servers are Oracle Linux. Here is... (21 Replies)
Discussion started by: duke0001
21 Replies

6. Shell Programming and Scripting

fatal: cannot open file `TNAME' for reading (No such file or directory)

Hi, I am running this command through a shell script and getting the error mentioned in the subject line: testing.awk -f x.txt TNAME My testing.awk file contains something like ++++++++++++++++++ #!/usr/bin/awk -f BEGIN{ TAB_NAME="INSERT_ONE_" ARGV ; } if ( $1=="JAM_ONE" &&... (1 Reply)
Discussion started by: kunwar
1 Replies

7. Red Hat

libodbc.so.1: cannot open shared object file: No such file or directory

We are trying to install third party software on this unix server... Here is the error message we are getting... error while loading shared libraries: libodbc.so.1: cannot open shared object file: No such file or directory It seems like odbc driver is not installed... >rpm -q unixODBC... (1 Reply)
Discussion started by: govindts
1 Replies

8. UNIX for Advanced & Expert Users

how to open a last modified file in a directory

how to directly open a last modified file in a directory? Please help (5 Replies)
Discussion started by: apsprabhu
5 Replies

9. Solaris

Error- ld.so.1: expr: fatal: libgmp.so.3: open failed:No such file or directory

Hi Friends I have a compiler(Sun Forte,I believe) running in my Solaris 9 box. since y'day my development team is finding this error when they compile: ld.so.1: expr: fatal: libgmp.so.3: open failed: No such file or directory I ran a search for this file and found it in one of my file... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

10. Programming

libRmath.so: cannot open shared object file: No such file or directory

% locate Rmath /m/backup/backup/lib/R/include/Rmath.h /usr/lib/R/include/Rmath.h % gcc -g -o stand stand.c -I/usr/lib/R/include/ -lRmath -lm % ./stand ./stand: error while loading shared libraries: libRmath.so: cannot open shared object file: No such file or directory What's the trouble... (6 Replies)
Discussion started by: cdbug
6 Replies
Login or Register to Ask a Question