Why cant?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Why cant?
# 1  
Old 08-02-2001
Why cant?

I need to verify wether a file is exist or not be4 i proceed to my next stage.

So i wrote it like tat:

if [ ! ' ls | grep '^data.dat' ' ]
then
.................
else
................
fi

But the result is not i want!!! Smilie

* i tried : if [ ' ! ls | grep '^data.dat' ' ] oso

Second...about the passing argument ot awk script.

I tried the way awk -f generate.awk data.dat awk_serial=$serial
But i dun seems to get access to awk_serial in the awk script.

When i try to echo $awk_serial there...they say file awk_serial not found.... Smilie

Pls help!! pls...pls.....Thx
# 2  
Old 08-02-2001
Try:
if [ -e /path/to/file ] ; then
.....
else
.....
fi


Also, with awk, when you define an external variable to an internal one, make sure the external is set... In clearer terms, see the following:

grep $1 $FILE | awk -F, -v ARG2=$2 '{print $1 $ARG2}'
(Example from one of my simple automation scripts at work, where $1 and $2 are the normal shell-assigned arguments.)

In this particular script, called grab, it is called like so:

./grab /*unique identifier*/ /*field number from flat file*/
i.e.- ./grab 015901492 43

That line looks for the unique identifier, then prints out the field number from the comma-delimited (that's what the "-F," is for) flat file I asked for, in the example, 43.

This might not make any sense, but I do hope it helps...

# 3  
Old 08-02-2001
I think the best thing for you could be the if - command from livinfree, so just some comments in addition:

man test - would bring you the expressions you can use with if

-e ... file exists
-f ... file is a regular file
-d ... file is a directory
-h ... symbolic link
-b ... block device
-c ... character device
# 4  
Old 08-02-2001
also
-s if the file size is non zero
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question