Implementing operators on multiple fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Implementing operators on multiple fields
# 8  
Old 05-29-2013
First create a file named: seq with all the numbers that you want to search:
Code:
$ cat seq
9100
9101
9102
9103
9104
9105
9106
9150
9151
9152
9153
9200
9201
9203
9300
9301
9302
9303
9304
9305
9400
9401
9510
9511

Now write an awk program to join seq and other input files:
Code:
awk -F, '
        NR == FNR {
                A[$1]
                next
        }
        $14 in A && $42 != 0 {
                ++c
        }
        END {
                print c > "pax1"
        }
' seq *_201304*.csv

# 9  
Old 05-29-2013
For reasons of performance, I would reverse the order of the tests, so you don't need to evaluate the entire array to finally find $42 being 0. And, you could use the implicit test for 0, leaving out "!=0":
Code:
         $42 && $14 in A {

This User Gave Thanks to RudiC For This Post:
# 10  
Old 05-31-2013
Thank you for all your help.
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