awk with multiple condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk with multiple condition
# 15  
Old 10-08-2009
for an example,

Code:
d02 $ cat file1
4 3.855143e-07 3.855143e-07
6 1.927572e-07 5.782715e-07
7 3.855143e-07 9.637858e-07
8 1.927572e-07 1.156543e-06
30 4.018987e-05 8.086162e-05
d02 $ awk '(NR != 1 || NR != 2) {print $0}' file1
4 3.855143e-07 3.855143e-07
6 1.927572e-07 5.782715e-07
7 3.855143e-07 9.637858e-07
8 1.927572e-07 1.156543e-06
30 4.018987e-05 8.086162e-05

I want only the first and third row, but it is returning all the records
# 16  
Old 10-08-2009
So it's quite the opposite Smilie

Code:
% cat infile 
4 3.855143e-07 3.855143e-07
6 1.927572e-07 5.782715e-07
7 3.855143e-07 9.637858e-07
8 1.927572e-07 1.156543e-06
30 4.018987e-05 8.086162e-05
% awk 'NR ~ /^[13]$/' infile
4 3.855143e-07 3.855143e-07
7 3.855143e-07 9.637858e-07

# 17  
Old 10-08-2009
you were awesome.. i apolgise for taking this in a merry go round style..

Can i know what is wrong with this awk statement?

Code:
awk 'NR = 1 || NR == 3 {print $0}' file1

Thanks again
# 18  
Old 10-08-2009
Quote:
Originally Posted by mac4rfree
you were awesome.. i apolgise for taking this in a merry go round style..

Can i know what is wrong with this awk statement?

Code:
awk 'NR = 1 || NR == 3 {print $0}' file1

Thanks again
To achieve what you want, you should change = to ==:

Code:
NR == 1

# 19  
Old 10-08-2009
pludi his solution resolved my problem.. but i like to know why my code is not working.

Code:
awk 'NR = 1 || NR == 3 {print $0}' file1



---------- Post updated at 02:39 PM ---------- Previous update was at 02:38 PM ----------

you the man.. that solved my issue....

Thanks dude..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to ignore multiple rows based on a condition

All, I have a text file(Inputfile.csv) with millions of rows and 100 columns. Check the sample for 2 columns below. Key,Check A,1 A,2 A, A,4 B,0 B,1 B,2 B,3 B,4 .... million rows. My requirement is to delete all the rows corresponding to all the keys which ever has at least one... (4 Replies)
Discussion started by: ks_reddy
4 Replies

2. Shell Programming and Scripting

Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script. i tried like below : cd lock if ; then rm exitup if ; then kb_shutdown kb_startup if ; then rm exitup if ;... (3 Replies)
Discussion started by: charanarjun
3 Replies

3. Shell Programming and Scripting

Reading multiple lines with condition

Hi guys, I need to read following lines and put them in same row …. text: Abcd5437_XYA0_B1_WXYZ_BE 99:00:14:42:55:01:d4:22 99:00:14:42:70:01:d4:22 99:00:14:42:55:03:a0:22 99:00:14:42:70:03:a0:22 ... (4 Replies)
Discussion started by: dc@bos
4 Replies

4. Shell Programming and Scripting

Multiple if condition

Hi, I wanted to satisfy two requirements to proceed to do a task One of them is to calculate between two metrics and the other to check one of the file not empty if the condition matches the above two, it should proceed with the task below is the snippet of it, however when i run the script... (3 Replies)
Discussion started by: ajothi
3 Replies

5. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

6. Shell Programming and Scripting

Multiple condition checking in bash

Hi All, I am trying to check if two variables have value assigned to it. i am doing it like if ] then echo "Please specify either single hostname or host file for the report" usage exit fi But its not working for it.Even i specify values for both variables it dont go... (6 Replies)
Discussion started by: kailash19
6 Replies

7. Shell Programming and Scripting

Combining multiple rows in single row based on certain condition using awk or sed

Hi, I'm using AIX(ksh shell). > cat temp.txt "a","b",0 "c",bc",0 "a1","b1",0 "cc","cb",1 "cc","b2",1 "bb","bc",2 I want the output as: "a","b","c","bc","a1","b1" "cc","cb","cc","b2" "bb","bc" I want to combine multiple lines into single line where third column is same. Is... (1 Reply)
Discussion started by: samuelray
1 Replies

8. Shell Programming and Scripting

multiple echo statements in if condition

Hi , I have a peculiar problem. i have an if block like this if ; then echo " todays date is " ${date} >> log_file echo " file count is " $ count >> log_file mv filename1 filename 2 else echo "no files available ">> log_file fi the echo statement "no files available " is not... (2 Replies)
Discussion started by: wizardofoz
2 Replies

9. Shell Programming and Scripting

multiple condition in if

All, My environment is Red Hat Enterprise Linux 5. I am using the following condition -- if -0 ] above command is not working. It is telling that -a unexpected. Please help me (10 Replies)
Discussion started by: user7509
10 Replies

10. UNIX for Dummies Questions & Answers

Multiple Condition If statement

Hi, I would like to create an IF statement where if a variable is equal to at least one of 2 (or more) values then the script proceeds. For example: TEST_VAR=2 if ; then echo success! else echo failure fi I understand that the above syntax is wrong but I feel it must be close. Any... (1 Reply)
Discussion started by: msb65
1 Replies
Login or Register to Ask a Question