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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fatal: cannot open file `TNAME' for reading (No such file or directory)
# 1  
Old 03-11-2011
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
++++++++++++++++++
Code:
#!/usr/bin/awk -f

BEGIN{
        TAB_NAME="INSERT_ONE_" ARGV[ARGC-1] ;
}

if ( $1=="JAM_ONE" && $2=="Starting" ) {
                print "insert into " TAB_NAME " (table_name) values('" $6 "');"

                print "\n";
        }
if ( $1=="JAM_TWO" && $2=="Finishing" ) {
                print "insert into " TAB_NAME " (table_name) values('" $6 "');"

                print "\n";
        }


....some other piece of code..

++++++++++++++++++

When i am trying to run this code:
Code:
testing.awk -f x.txt TNAME

It gives me a error (which i think is because of the fact it is trying to see TNAME as a file).
Code:
awk: testing.awk:32: (FILENAME=./X/X//x.txt FNR=4) fatal: cannot open file `TNAME' for reading (No such file or directory)


Can anyone suggest how to resolve the error? How to modify my code such that the last parameter in the command given above doesn't take it as a file name. I think it is trying to resolve the last parameter as a file and throwing this error.
I call the above command through a different shell script's for loop

Code:
for file_name in $xdir/*.done
        do
                if [[ -f $file_name ]]
                then
                testing.awk -f x.txt TNAME >> $command_file
                fi
       done

Moderator's Comments:
Mod Comment Please use [code] tags for listings, console output, ...

Last edited by pludi; 03-11-2011 at 09:57 AM..
# 2  
Old 03-11-2011
Code:
testing.awk -f x.txt TNAME

tells awk to process the file TNAME, which it cannot find

-f switch is used to tell awk to read the commands from file. So you probably wanted to call it like this:
Code:
awk -f testing.awk x.txt

You're still gonna get into trouble though... I'd suggest you use -v switch to awk to pass it a variable that you can use inside your script:
Code:
awk -v "TNAME=blah" '{print "TNAME has value: " TNAME}'

Perhaps you wanted to do this:
Code:
testing.awk -v "TNAME=blah" x.txt

to process the file x.txt with variable TNAME set to value "blah"
This User Gave Thanks to mirni For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Programming

Fatal error: mcrypt.h: No such file or directory

Hi All, I am trying to include a mcrypt.h header but I am getting the below error: test01> gcc test1.c test1.c:5:20: fatal error: mcrypt.h: No such file or directory #include <mcrypt.h> ^ compilation terminated. As I cannot put my encryption program here, so have... (4 Replies)
Discussion started by: Shre
4 Replies

3. 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

4. Shell Programming and Scripting

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. #!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... (10 Replies)
Discussion started by: radiohead_
10 Replies

5. Solaris

fatal error: stdio.h: No such file or directory

Trying to compile a C program recievin this hello.c:1:19: fatal error: stdio.h: No such file or directory gcc is installed on the system. echo $PATH /usr/bin:/usr/sbin:/usr/gcc/4.5/include/c++/4.5.2/tr1 root@Sol11swtb01:/media/NO NAME/Programming/C/Testing# cd... (2 Replies)
Discussion started by: Fingerz
2 Replies

6. 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

7. 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

8. 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

9. Shell Programming and Scripting

Reading a file that is already open by another process

hi, I'm using HP unix tru64 & Win XP. i'm download a file from winxp to unix using ftp. how to know whether a remote file is currently being used by the process or not? (my loaction unix server) (7 Replies)
Discussion started by: Tlg13team
7 Replies

10. Shell Programming and Scripting

getting error 0403-016 Cannot find or open the file while reading a long line

Hi, I have an requirement of reading a long line of 7000 chars and cutting it iam doing this : while read -r x do echo $x ......... done < `cat filename` when iam doing this it is giving me "0403-016 Cannot find or open the file." Can anyone let how this can be done. (2 Replies)
Discussion started by: karthee
2 Replies
Login or Register to Ask a Question