awk returns null?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk returns null?
# 1  
Old 10-01-2009
awk returns null?

hi
i try to check if awk returns null
and i dont know how it's works

this is the command
set EndByC = `ls -l $base | awk '/.c$/ {print $9}'`
if ($EndByC=="") then #check if ther is XXX.c directory
echo Sorry ther is no XXX.c folder "in" $base path
echo the XXX.c folder is necessary to build the Makefile, please check again the path of this folders
exit 1
10X
or
# 2  
Old 10-01-2009
Hi.

Are you testing if any C files exist?

You can use something like
Code:
ls $base/*.c > /dev/null 2>&1
if [ $? -ne 0 ]; then #no files
  echo Sorry ther is no XXX.c folder "in" $base path
  echo the XXX.c folder is necessary to build the Makefile, please check again the path of this folders
  exit 1
fi

ls will return an error (2) if no files exist, so there's really no need for awk, actually.

Assuming "$base" is a directory, ls will never return "NULL" with the -l option.

Code:
mkdir BLAH
ls -l BLAH
 
total 0

# 3  
Old 10-01-2009
awk doesn't/can't return null. It's return (as an int) can be set by the exit directive....
# 4  
Old 10-01-2009
Quote:
Originally Posted by jp2542a
awk doesn't/can't return null. It's return (as an int) can be set by the exit directive....
I believe the O/P means an empty string.
# 5  
Old 10-01-2009
ok
$base is a directory that should end with ".c" so i wont to check if any XXX.c dirs are exist
what it's > /dev/null 2>&1
end [ $? -ne 0 ]?
# 6  
Old 10-01-2009
Ok, too much!

Code:
if [ -d $base ]; then
  echo directory $base exists
else
  echo directory $base does not exist
fi


Worry about the other stuff later...
# 7  
Old 10-01-2009
sorry again
$base - is the path that given to the script
and in this path($base) i need a list of all the ???.c directory
and if there is not ???.c dir.. print error
???.c-(any directory that end with .c)
ok?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove carriage returns from awk output

I'm on Linux version 2.6.32-696.3.1.el6.x86_64, using the Ksh shell. I'm working with the input file: John Daggett, 341 King Road, Plymouth MA Alice Ford, 22 East Broadway, Richmond VA Orville Thomas, 11345 Oak Bridge Road, Tulsa OK Terry Kalkas, 402 Lans Road, Beaver Falls PA Eric Adams,... (2 Replies)
Discussion started by: prooney
2 Replies

2. Shell Programming and Scripting

awk print columns which are not null

I am working on a file with several columns as below MO_NAME,FAULT_TYPE,CLASS,CODE1,CODE2,CODE3 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,53,58 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2B,24 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,33 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2D,57 ... (12 Replies)
Discussion started by: Rizwan Rasul
12 Replies

3. Shell Programming and Scripting

Awk script returns nothing

HSLIST=$1 LFILE=$2 STRING=$3 awk 'BEGIN { while((getline < "'${HSLIST}'")>0) S FS="\n"; RS="}\n" } /servicestatus {/ && /service_description='${STRING}'/ { for(X in D) delete D; for(N=2; N<=NF; N++) { split($N, A, "="); (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

awk print last line returns empty string

hello I have a file with lines of info separated with "|" I want to amend the second field of the last line, using AWK my problem is with geting awk to return the last line this is what I am using awk 'END{ print $0 }' myFile but I get an empty result I tried the... (13 Replies)
Discussion started by: TasosARISFC
13 Replies

5. Shell Programming and Scripting

for loop returns more output with awk

I need to get total number of hdisk not assigned to any VGs. PDC # lspv |grep None |awk '{print $1}' |wc 131 131 1099 So, it shows 131 hdisks. I need to look at the individual hdisk fget_config info like below: PDC # fget_config -Av |grep hdisk230 hdisk230 dac1 229... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

6. Emergency UNIX and Linux Support

Adding carriage returns to file using sed/awk

Hello, I need help adding carriage returns at specific intervals (say 692 characters) to a text file that's one continous string. I'm working in AIX5.3. Any quick help is appreciated. Thanks! (2 Replies)
Discussion started by: bd_joy
2 Replies

7. UNIX for Dummies Questions & Answers

echo statement when find returns null

Hi, How do you echo something once when a find statement returns null results? This is when using mutiple locations and mutiple arguments. The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations. find... (2 Replies)
Discussion started by: tchoruma
2 Replies

8. Shell Programming and Scripting

awk returns an integer?

I need to extract a value from a text file into a ksh script, and change the last two letters to "00". awk gets the right value (2500 in this example), but the variable has no value. I use the following command: StartTime=expr nawk 'NR==20 {print $11;exit}' $New_FILE echo 1 $StartTime... (4 Replies)
Discussion started by: Iliklev
4 Replies

9. Programming

PEM_read_RSAPublicKey returns NULL

Hi all, I am trying to write a program in C which will generate private and public keys using openssl RSA and use these for encryption and decryption. I am able to generate the keys successfully and write these to files. I am able to read the private key successfully. I can encrypt and decrypt... (1 Reply)
Discussion started by: Treasa
1 Replies

10. IP Networking

gethostbyname_r returns NULL when hostname has dash

We have a code to find the DNS entry of a host that has a trailing '-' in its url (format example: mysite-.watch.com): if(gethostbyname_r(host,host_ent,host_buffer,host_buffer_size,&host_error)==NULL) { //failed } But when remove the '-' from the host name the code does not return... (12 Replies)
Discussion started by: uunniixx
12 Replies
Login or Register to Ask a Question