Printing records which meet condition using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing records which meet condition using awk
# 1  
Old 05-19-2009
Printing records which meet condition using awk

Below is the code

Code:
nawk -F"|" 'tolower($1) ~ "abc" |"" {if (tolower($2) ~"abc"|"") print$0}' file

I want the records from file whose 1st and 2nd field should be either "abc" or "null"
I tried but its giving error.
Appreciate help
# 2  
Old 05-19-2009
Code:
awk ' $1 ~/abc/ || $1=="" || $2 ~/abc/ || $2=="" '  inputfile

# 3  
Old 05-19-2009
Quote:
Originally Posted by jim mcnamara
Code:
awk ' $1 ~/abc/ || $1=="" || $2 ~/abc/ || $2=="" '  inputfile

Thanks jim mcnamara
I modified the code to look for lower or uppercase.The below code was still giving output lines which did not had "abc" or null in 1st and second field.

Code:
nawk -F"|" ' tolower($1) ~ "abc" || $1=="" && tolower($2) ~"abc" || $11=="" ' file

Then i modified it as below.This does what i want.
Code:
 nawk -F"|" ' tolower($1) ~ "abc" || $1=="" {if(tolower($2) ~"abc" || $11=="") print}' file

as both the codes have the same logic
Please help me understand whats the difference.

And i see sometime we use
Code:
$1 ~/sting/

and sometime
Code:
$1 ~"string"

Please help me understand.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk do not split if condition is meet

Trying to use awk to format the input based on the filed count being 5. Most lines are fine using the awk below, except the first two lines. I know the reason is the -1 in green and -2 in blue. But can not figure out how to not split on the - if it is followed by a digit then letter. Thank you :).... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

awk to capture lines that meet either condition

I am trying to modify and understand an awk written by @Scrutinizer The below awk will filter a list of 30,000 lines in the tab-delimited file. What I am having trouble with is adding a condition to SVTYPE=CNV that will only print that line if CI=,0.95: portion in blue in file is <1.9. The... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Getting the records once condition met

Hi All, Seeking for your assistance to get the records once the $2 met the condition. Ex. file 1.txt 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 123232,11-Aug-2015 08:33:37 PM,4234324,1321432,34364 Output: 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 What i did... (5 Replies)
Discussion started by: znesotomayor
5 Replies

4. Shell Programming and Scripting

Deleting the records based on the condition

Hi, Can any one help me, in deleting the records from the database table based on the following condition: script should take a configurable parameter as input. The input is nothing but “no. of years”. For example, if I enter 2 as input parameter, then the 2 year old records should get... (2 Replies)
Discussion started by: zxcjggu708
2 Replies

5. Shell Programming and Scripting

Printing symbols with some condition

hi ..all I have an urgency of doing some task so I am posting here...please help i tried this ...its not working properly awk '{if($1>p)print $0;else $1=$2="*";print $0}'pls find attachment my input file is like this 0 25.2 11-Jan-1971 6.45 1040 SU 1 25.2 ... (3 Replies)
Discussion started by: Dona Clara
3 Replies

6. Shell Programming and Scripting

Delete records within a file upon a condition

Hi Friends, I have the following file, cat input chr1 1000 2000 chr1 600 699 chr1 701 1000 chr1 600 1710 chr2 900 1800 Now, I would like to see the difference of Record1.Col2 - Record2.Col2 Record1.Col2 - Record2.Col3 Record1.Col3 - Record2.Col2 Record1.Col3 - Record2.Col3 ... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

7. Shell Programming and Scripting

Counting the records based on condition

Hi Unix team, I have a file with 30 columns with tab delimited. I need to count the records based on column 18 & 21 data. So I cut the data from the file using awk -F"\t" '{print $18,$21}' foo.txt Following is the output: USED SEDAN USED SUV NEW SUV USED Truck USED Truck USED... (6 Replies)
Discussion started by: karumudi7
6 Replies

8. UNIX for Dummies Questions & Answers

Printing records in different format

Hi all, I have a input file say record.txt hostname IP_address Port_No Version A 10.10.10.1 80 6.02 B 10.10.10.2 81 6.03 C 10.10.10.3 82 6.04 row 1 has 4 field headings : hostname, IP_address, Port_No and Version. and from 2nd row onwards the actual records start. now i need to... (2 Replies)
Discussion started by: PranavEcstasy
2 Replies

9. Shell Programming and Scripting

Print other records along with condition too

Hi, I have a text file with more than 100000 records. I used the following command awk '{if ($3<$2) print $1"\t"$3"\t"$2"\t"$4"\t"$5}' input.txt > output.txt But, this one is printing which satisfies the condition, which are only 1000. I would like to get all the 100000 records in... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

10. Shell Programming and Scripting

Script printing else condition

Please help what is wrong in below script. It is printing else also, else echo "DATABASE NOT RUNNING :${i} ================================================= #!/usr/bin/ksh set -A DBS $(cat /etc/oratab | grep ":Y" | awk -F : '{print $1}') set -A RDBS $(ps -ef | grep -i pmon | grep... (3 Replies)
Discussion started by: allwin
3 Replies
Login or Register to Ask a Question