Logical AND, OR not working with awk.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Logical AND, OR not working with awk.
# 1  
Old 12-02-2008
Logical AND, OR not working with awk.

awk -F^ '{ if ((($1 == "M") && ($5 == "2")) || (($1 == "S") && ($5 == "7"))) print $0}' welcome > welcome1

When I run the above awk command, I could see the same content of welcome in welcome1.

Later, I found that the logicals "&&", "||" used in the above command is not working.

Can any intelligent awk'ers suggest a better method of using logicals in the above command.

Thanks in advance.
# 2  
Old 12-02-2008
For me it is perfectly working:


imac ~ # cat inp
S^it^201^INF^Gur^Del
M^it^201^FCS^2^Wew
F^it^201^FCS^Gur^Del
S^it^201^COG^7^Dda

imac ~ # awk -F^ '{ if ((($1 == "M") && ($5 == "2")) || (($1 == "S") && ($5 == "7"))) print $0}' inp
M^it^201^FCS^2^Wew
S^it^201^COG^7^Dd

No issues at all... Please check your input file.
# 3  
Old 12-02-2008
Can you try working of this below command.

awk -F^ '{ if ((($1 != "M") && ($5 != "2")) || (($1 != "S") && ($5 != "7"))) print $0}' welcome > welcome1
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: System command not working in awk

Hi, I have around 10 files in a folder in which I want to change the file format from tab(\t) to pipe(|) with some changes in the fields as well. Below is the code, while tmp file is getting generated but move command is not working, please help Following is the code awk -F"\t" '{print... (2 Replies)
Discussion started by: siramitsharma
2 Replies

2. Shell Programming and Scripting

awk - why this is not working? trying next word!

Hi Experts, Can you please advise , why I am not able to make it work, or why this is not working: I spent quite a lot of time on this figuring out , but not working, file : This is a test file thanks for your reply This is another file again Have a nice day this is a small file... (3 Replies)
Discussion started by: rveri
3 Replies

3. Shell Programming and Scripting

awk help : if then else not working!

Hi All, This code is not working when trying with "else" : Am I missing something, uptime|sed 's/,/ /g' | awk '{ if ($10 >1) { print ( " :: UPTIME GT 1 : ALERT" )} ;else print "OK" }' Getting this error: syntax error The source line is 1. The error context is { if... (4 Replies)
Discussion started by: rveri
4 Replies

4. Shell Programming and Scripting

awk comparison not working

Can you please help me on belw awk comparsion which doest not work cat employee_list NAME Last-login Jack 03/25/2013 Maneul 03/26/2013 Eric 03/26/2013 Samuel 03/28/2013 loak 03/29/2013 zac 03/29/2013 this is my awk .. it gives me error cat employee_list | awk '(($2=='date... (3 Replies)
Discussion started by: Sara_84
3 Replies

5. Shell Programming and Scripting

[awk] working with two files

Hello guys, I have little to no experience working with two files in awk and hope you can help me with a problem that may be easy for you to solve... awk -v cut1="$var1" -v cut2="$var2" '{split($0, arr1); for(i=1;i<=NF;i++) if (arr1 < cut1) print arr1, NR, i}' file1 file2 The above code is... (4 Replies)
Discussion started by: origamisven
4 Replies

6. Shell Programming and Scripting

Using Logical Expression in an AWK statement

I'm would to create a script that would give me the results below. Please note the spaces in the log file are actually commas(",".) Log file Data 0:00 21:15 899 43 31 12 25.39 0:00 21:20 736 34 19 15 35.39 0:00 21:20 776 41 28 13 ... (3 Replies)
Discussion started by: ravzter
3 Replies

7. UNIX for Advanced & Expert Users

Awk expressions working & not working

Hi, Putting across a few awk expressions. Apart from the last, all of them are working. echo a/b/c | awk -F'/b/c$' '{print $1}' a echo a/b/c++ | awk -F'/b/c++' '{print $1}' a echo a/b/c++ | awk -F'/b/c++$' '{print $1}' a/b/c++ Request thoughts on why putting a '$' post double ++... (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

8. Shell Programming and Scripting

How to do logical AND and logical OR with grep

Hi can someone please help me on this. I need to perform this code: Grep any lines that meets the following criteria (A AND B) OR (A AND C) I tried this code, but it didn't work Grep-I "A &&B" | "A&&C" *.* $ thanks in advance (12 Replies)
Discussion started by: Needhelp2
12 Replies

9. Shell Programming and Scripting

awk not working in script

Hi All, i'm trying awk commnad to read only file names with the help of below command :- ls -l tmp*.txt | awk { 'print $9' } | head -1 The command is working fine :o on command line, but when i trying it in script then its not working $var1=`ls -l tmp*.txt | awk { 'print $9' } | head -1`... (3 Replies)
Discussion started by: doitnow
3 Replies

10. Shell Programming and Scripting

awk not working for me.

Hi All, I have a server.xml file which looks something like. <Connector port="8443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100"... (2 Replies)
Discussion started by: nua7
2 Replies
Login or Register to Ask a Question