Get the awk cmd for two condition

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the awk cmd for two condition
# 1  
Old 01-03-2014
Get the awk cmd for two condition

Hi All,

i have following cmd to get a “n/a” value from one particular column, but if i need to take one column n/a value with based on other column this cmd will help?

col1    col2    col3
234    RR    Yes
n/a    RR1    No
236    RR2    No
237    RR3    Yes
238    RR4    No
n/a    RR5    Yes

from this using following cmd
awk -F\\t '{ if (NR == 1) { for (i=1;i<=NF;i++){if ($i=="col1") { c=i } } };if (NR 
!= 1) {if ($c ~ /n\/a/ ) print $2 }}' file.tsv

I will get the list of col2 which have n/a in col1,

if i want col2 value have "n/a" and does not contained "yes" on col3.
how can i change this cmd.

Last edited by radoulov; 01-03-2014 at 05:09 PM..
# 2  
Old 01-03-2014
Originally Posted by Shenbaga.d
if i want col2 value have "n/a" and does not contained "yes" on col3.
Is this what you are looking for?
awk -F'\t' 'NR==1{print;next}$1=="n/a"&&$3!="Yes"' file.tsv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk cmd for vlookup in Mysql

Hi, Is there possible to do vlookup in Mysql one table from another table based on one column values and placed the data in same table? if it is possible in mysql itself pls share links for reference. Here is the ex: i need to vlookup the in table to and place the in 4th... (3 Replies)
Discussion started by: Shenbaga.d
3 Replies

2. Shell Programming and Scripting

Invoking system(cmd) inside awk command

Hi, I was searching for a way to grep 2 lines before and after a certain keyword, and I came across the following code.. awk "\$0 ~ /ORA-/ { cmd=\"awk 'NR>=\" NR-2 \" && NR<=\" NR+2 \"' init.ora\" system(cmd) }" input_file I could not understand how this works. What is system() ? what... (2 Replies)
Discussion started by: Kulasekar
2 Replies

3. Shell Programming and Scripting

Awk: cmd. line:1: fatal: division by zero attempted

when i try the snippet in the console its working fine: ps awwwux | grep php-fpm | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' output: but when i try the bash script: #!/bin/sh # -*- sh -*- #... (3 Replies)
Discussion started by: danieloooo
3 Replies

4. 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

5. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

6. Shell Programming and Scripting

Capturing awk's system(cmd) output

Hi everybody, I am working on a bigger awk script in which one part is comparing the size of two files. I want to evaluate which file is bigger and then just save the bigger one. I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently... (2 Replies)
Discussion started by: iMeal
2 Replies

7. Shell Programming and Scripting

Combining many lines to one using awk or any unix cmd

Combining many lines to one using awk or any unix cmd Inputfile: Output : Appreciate help on this. (14 Replies)
Discussion started by: pinnacle
14 Replies

8. HP-UX

awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print. .... | awk '{print $0}' I would like it to print the date right before $0, so something like (this doesn't work though) .... | awk '{print date $0}' (4 Replies)
Discussion started by: IMTheNachoMan
4 Replies

9. Shell Programming and Scripting

Help with awk cmd

Hi All, I am trying to read a file as input and pull out some information from the file and put it into another file in column format and then take that file and make it an excel file. My problem is that I'm trying to put the date in one of the columns using a variable in an awk cmd, but when I... (4 Replies)
Discussion started by: New2Scripting
4 Replies

10. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question