can you explain this AWK "c+" statement ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users can you explain this AWK "c+" statement ?
# 1  
Old 10-01-2004
can you explain this AWK "c+" statement ?

Well i use the following statement in a script to calculate the all column value of a ls command :

find . -name *.leon -exec ls -al {} \;|awk '{c+=$5} END {print c}'

And this is the result :
2.34546e+09

i would know what is exactly the "c+" role , and what i must modify to have the result in bytes :
2345460000

thanks in advance

christian
# 2  
Old 10-01-2004
The "c+=$5" means that for each record, the value of the fifth field should be added to whatever the value of c already is - i.e., it has the effect of summing all values in the fifth field of the data.

This is equivalent to saying

c = c + $5

Cheers
ZB
# 3  
Old 10-01-2004
Sorry, just saw your second question.

Change the awk to have this at the end
END {printf "%d\n", c}'

Cheers
ZB
# 4  
Old 10-01-2004
running this :

find . -name *.nsf -exec ls -al {} \;|awk '{c+=$5} END {printf "%d\n", c}'

i got :

find: missing conjunction
0

some mistake ??? and what 's the difference ?

thanks

christian
# 5  
Old 10-02-2004
Strange.... that command works fine under my system (Linux).

Try including a -print (even though it shouldn't be necessary)

find . -name *.nsf -print -exec ls -al {} \;|awk '{c+=$5} END {printf "%d\n", c}'

Cheers
ZB
# 6  
Old 10-04-2004
Well i don't know why , this works if i put "*.nsf" in place of *.nsf
maybe this is related to the number of files concerned ??

christian
# 7  
Old 10-04-2004
I (or somebody else) should have noticed that....

All globbing (i.e. wildcard matches) within finds must be "quoted", e.g. "*.thisworks" but *.thisdoesnt.

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

"if" statement based off "grep"

Hello, I am somewhat new to Linux/Unix. I am currently working on a shell script that is suppose to cat a file, grep the same file for a certain line, if that line is found save the file in a different location, else remove the file. This is a rough example of what I want. $Dating = False... (13 Replies)
Discussion started by: Amzerik
13 Replies

2. UNIX for Dummies Questions & Answers

What is the meaning of "-s" option in "if" statement?

Hi Guys, I'm sorry but I can't find answer for this, what is the meaning of -s option in "if" statement on unix scipting. Please see sample below: opath=/home/output for i in N1 N2 N3 N4 do echo $i if then grep $i $opath/N5_CRAI > $opath/N5_$i.crai chmod 777 $opath/N5_$i.crai ... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

Awk find in columns with "if then" statement and print results

I have a file1.txt file1.txt F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true" F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true" U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"... (4 Replies)
Discussion started by: charles33
4 Replies

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

6. Shell Programming and Scripting

What "-a" operator means in "if" statement

Hi I am trying to figure out what the following line does, I work in ksh88: ] && LIST="$big $LIST" Not sure what "-a" means in that case. Thanks a lot for any advice -A (1 Reply)
Discussion started by: aoussenko
1 Replies

7. Red Hat

"if" and "then" statement is not working in RedHat

Dear experts, I'm trying to write a script to calculate the usage of Log Archive in a directory, so if it gets to a point where the directory size is 60%, then send out an FYI.. email. So if then it reaches to 80%, move the logs from that directory. I have written the script as follow but... (10 Replies)
Discussion started by: Afi_Linux
10 Replies

8. Shell Programming and Scripting

awk statement to match all lines starting with "#"

Looking for awk statement that will match all lines starting with "# " if ( $1 == \^"#" ) Input file: # of the server. If you would like to set these, please take out the # pound (#) sign in front of one or all severities and set it equal to # severity desired. For example, FATAL=3 #... (2 Replies)
Discussion started by: Arsenalman
2 Replies

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

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