Visit Our UNIX and Linux User Community


awk with multiple condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk with multiple condition
# 8  
Old 10-07-2009
ya guys, thanks for the solution..
So, its not possible with awk ???
# 9  
Old 10-07-2009
Quote:
Originally Posted by mac4rfree
ya guys, thanks for the solution..
So, its not possible with awk ???
Danmero already provided an awk solution.

Here's another one:

Code:
awk 'NR!~/^[13]$/' infile

# 10  
Old 10-07-2009
Code:
awk '(NR != 1 && NR != 2) {print $0}' < filename>

, it should be &&

Last edited by radoulov; 10-07-2009 at 11:51 AM.. Reason: Use code tags, please!
# 11  
Old 10-08-2009
Guys, i think i have not explained myslef well..

I dont want an AND (&&) condition. I want an OR (||) condition.

The problem is awk is working with AND condition but it is not working with || condition
When i am using || condition, it is giving all the records instead of the two records i needed.

Hope i made myself clear
# 12  
Old 10-08-2009
Quote:
Originally Posted by mac4rfree
I just wanted to print all the lines execpt 1st and 3rd line
Quote:
Originally Posted by mac4rfree
i do not want both the 1st and 3rd line
So what exactly is wrong with this solution? It's just boolean logic: !(line 1 or line 3) == !line 1 and !line 3
# 13  
Old 10-08-2009
actually i want !line 1 or !line 3.. which is not working
# 14  
Old 10-08-2009
Quote:
Originally Posted by mac4rfree
actually i want !line 1 or !line 3.. which is not working
What should be the output given the following input:
Code:
zsh-4.3.10[t]% print -l line{1..5}                               
line1
line2
line3
line4
line5

Which lines should appear?

Given your last comments, I suppose that you don't want this:

Code:
zsh-4.3.10[t]% print -l line{1..5}|awk 'NR !~ /^[13]$/'
line2
line4
line5


Previous Thread | Next Thread
Test Your Knowledge in Computers #798
Difficulty: Medium
To convert from a base-10 integer to its base-2 (binary) equivalent, the number is divided by two and the remainder is the least-significant bit.
True or False?

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

Featured Tech Videos