Implementing operators on multiple fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Implementing operators on multiple fields
# 1  
Old 05-29-2013
Implementing operators on multiple fields

Hallo Friends,

Have a look at my script:

awk -F',' '$14==9100' *_201304*.csv|wc -l > pax1;
awk -F',' '$14==9101' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9102' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9103' *_201304*.csv|wc -l >>pax1


I would like to include field 42. like below

HTML Code:
awk -F',' ['$14==9101' , '$42!=0'] *_201304*.csv|wc -l > pax1
Basically my script is saying if field 14 = 9101 and field 42 is not zero then wc -l . Please help with my syntax

Regards,
# 2  
Old 05-29-2013
How about this?
awk -F',' '$14~/910[0123] && $42 != 0' *_201304*.csv | wc -l > pax1

Here 910[0123] will evaluate to 9100, 9101, 9102, 9103

regards,
juzz4fun
This User Gave Thanks to juzz4fun For This Post:
# 3  
Old 05-29-2013
Code:
awk -F',' ' if ($14==9101' && $42!=0) ' *_201304*.csv|wc -l > pax1

This User Gave Thanks to Fundix For This Post:
# 4  
Old 05-29-2013
-bash-3.2$ awk -F',' ' if ($14==9101' && $42!=0) ' *_201304*.csv|wc -l > pax1
-bash: syntax error near unexpected token `)'
-bash-3.2$
# 5  
Old 05-29-2013
Create a script:

Code:
for i in *_201304*.csv
do awk -F',' '$14~/910[0123]/ && $42 != 0' $i | wc -l >> parx1
done

Hope this helps..
This User Gave Thanks to juzz4fun For This Post:
# 6  
Old 05-29-2013
can we implement that on the rest:
Code:
awk -F',' '$14==9100' *_201304*.csv|wc -l > pax1;
awk -F',' '$14==9101' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9102' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9103' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9104' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9105' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9106' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9150' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9151' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9152' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9153' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9200' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9201' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9203' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9300' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9301' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9302' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9303' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9304' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9305' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9400' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9401' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9510' *_201304*.csv|wc -l >>pax1;
awk -F',' '$14==9511' *_201304*.csv|wc -l >>pax1


Last edited by Franklin52; 05-30-2013 at 03:41 AM.. Reason: Please use code tags
# 7  
Old 05-29-2013
Looks difficult for me to express all these using single regexp/pattern, but surely you can do that using multiple awk.
This User Gave Thanks to juzz4fun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Repeating Multiple Fields

I am trying to find a way to repeat fields. I am not really sure how to explain it so let me just post a sample and what I want it to look like. 888123 66232 18 1 19 44422 11 7 23 881133 66231 33 1 34 ... (4 Replies)
Discussion started by: DerangedNick
4 Replies

2. Shell Programming and Scripting

How to use logical operators in multiple if statement

Hi I want to send a status mail if daily or weekly or monthly batch completed or aborted. Here is the code. if && && || Else if && && || Else if && && || then mailx –s “Status Report” sumone@sumthing.com else print ”try again” Plz suggest the changes. (3 Replies)
Discussion started by: Avi
3 Replies

3. Shell Programming and Scripting

ksh Multiple Pattern Matching Operators

I figured this would be simple, but I am stuck. Variable longpath="/dir1/dir2/dir3/filename.stuff.morestuff.garbage" I want to end up with just "filename.extra.moreextra". So, I want to get rid of the path and .garbage I want to do this with just ksh internals. So, no sed,grep,awk,expr,... (4 Replies)
Discussion started by: Topaz
4 Replies

4. UNIX for Dummies Questions & Answers

Formatting Multiple fields on 1 line to multiple rows

I'm trying extract a number of filename fields from a log file and copy them out as separate rows in a text file so i can load them into a table. I'm able to get the filenames but the all appear on one line. I tried using the cut command with the -d (delimiter) option but cant seem to make it... (1 Reply)
Discussion started by: Sinbad-66
1 Replies

5. UNIX for Dummies Questions & Answers

issue with multiple logical operators

Hi, shell is /bin/ksh I am trying to do the following in my code.. but its showing me an error if ] && ] ]]; then echo "id is $ida and chk_dy is $chk_dy" fi the error I get is syntax error at line 23 : `"$ida"' unexpected I need to execute the... (2 Replies)
Discussion started by: nss280
2 Replies

6. UNIX for Dummies Questions & Answers

Need help with Join on multiple fields

Hi, I need help with the join command I have 2 files that I want to join on multiple fields. I want to return all records from file 1 I also want empty fields in my joined file if there isn't a match in file 2 I have already sorted them so I know they are in the same order. file1 ... (0 Replies)
Discussion started by: shunter0810
0 Replies

7. Shell Programming and Scripting

sort on multiple fields

Hello All I have data in a flat file with numeric and aplha numeric datatypes. Now i have to sort on multiple fileds. Can any body please give me the sort code? i am particularly confused about the sort code like sort -n +0 -1 +1 -2 .... (1 Reply)
Discussion started by: vasuarjula
1 Replies

8. Shell Programming and Scripting

sort on multiple fields

hello all I have a file names xxx with data like 1,2,3,12 1,3,6,12 1,3,5,12 2,4,6,12 6,5,6,12 4,2,7,12 4,1,3,12 I wish to sort this file xxx on first three fields in ascending order. OUPUT should be like 1,2,3,12 1,3,5,12 1,3,6,12 2,4,6,12 (4 Replies)
Discussion started by: vasuarjula
4 Replies

9. Shell Programming and Scripting

join on multiple fields

Is it possible to do a join on multiple fields of two files? I am trying to do something like join -t, -1 2,3 -2 2,3 -o 2.1,2.2,2.3,1.3 filea fileb I want the join to be on columns 2 and 3 of filea and columns 2 and 3 of fileb. What is hapenning is that the second file that I want to do the join... (1 Reply)
Discussion started by: reggiej
1 Replies

10. Programming

Bit-fields and Bitwise operators

Hi, Is it possible to use bitwise operators in bit fields? For example: typedef struct Mystruct { unsigned char A :1 ; unsigned char B :1 ; } Mystruct; and assume struct Mystruct STR_1S, STR_2S, tempSTRS = {0}; then the following line: tempSTRS = STR_1S & STR_2S; gives the... (3 Replies)
Discussion started by: amatsaka
3 Replies
Login or Register to Ask a Question