awk to substitute third column if first column is greater than interest


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to substitute third column if first column is greater than interest
# 1  
Old 02-12-2013
awk to substitute third column if first column is greater than interest

A file
Code:
2400  2800  PSC000289
3200  3896  PCS000289
3333  3666  PCS000221
222    1000  PCS000222
3299   3600  PSC000289

Code:
Question is while if third column is  PCS000289 
and first column should be greater than 3000, then replace PCS000289 by YES,
remaining the others column same.

Code:
the output file should be
2400  2800  PSC000289
3200 3896  YES
3333 3666  PCS000221
222    1000  PCS000222
3299 3600   YES

Code:
awk '{if (($3="PSC000289") && ($1>3000)) {gsub(/PSC000289/ ,"YES")};1'}  <file

but it is not working? any guess.
# 2  
Old 02-12-2013
Code:
awk '$3=="PCS000289"&&$1>3000{$3="YES"}1' file

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Substitute first column based on second column

Hi, I have files with lines that look like HSQ1008:141:D0CC8ACXX:3:1106:17255:124378 163 chr14 I'm wondering how I can output a file that appends /1 if the second column is 99 or 83 and a /2 if the second column is 163 or 147. Also I want to put \n + \n between each the second... (1 Reply)
Discussion started by: jyu429
1 Replies

2. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. UNIX for Dummies Questions & Answers

How can i substitute a header column?

Hi, I have a txt file with multiple columns and i want to substitute the header of the first column. Example: Seq. Name Seq. Length #Hits min. eValue mean Similarity #GOs GOs Enzyme Codes InterProScan comp1000201_c0_seq1 ---NA--- 337 0 0 - comp1000297_c0_seq1 ---NA--- 612 0 0 -... (4 Replies)
Discussion started by: alisrpp
4 Replies

4. Shell Programming and Scripting

Egrep a number greater than in a column

i'm aware awk can do what i'm trying to do here. but i cant use awk in this scenario given the circumstance of this box. but i need to check if a number is a certain column is over a certain value, say for instance, 20. data: | 12 | 19 | 2000 | 9029333 |... (11 Replies)
Discussion started by: SkySmart
11 Replies

5. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

6. Shell Programming and Scripting

substitute in first column

Hi, I have a file which has multiple columns in and i want to replace first column with : in between them. input_file 21000012343456 asdf 21000012343478 asd3 21000012343423 asdf 21000012343445 asdf 21000012343489 asdf output file 21:00:00:12:34:34:56 asdf 21:00:00:12:34:34:78 asd3... (6 Replies)
Discussion started by: jpkumar10
6 Replies

7. Shell Programming and Scripting

Greping the column with a value greater than 50 with awk

Hi All, I am running a command from a remote server using ssh to different servers. I will get a output like below with 4 columns. I want to grab line which is having a coulmn which grate than or equal to 50. How can I do it with Awk or sed ??. I add a space to first row with sed 's/::/:: /g' to... (4 Replies)
Discussion started by: raghin
4 Replies

8. Shell Programming and Scripting

AWK/SED print if 2nd character in a column is greater than 0

We have an access log where column 8 displays the time in seconds like below: Tj8nQAoNgwsAABov9cIAAAFL - 10.13.131.80 - - (0) - "GET /aaaaa/bbbb/bbbb where column 8 is printed (0). We are trying to find how many entries are there that has column 8 greater than 0. Remember $8 is (0) and not... (5 Replies)
Discussion started by: spacemtn5
5 Replies

9. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

10. Shell Programming and Scripting

using awk to substitute data in a column delimited text file

using awk to substitute data in a column delimited text file hello i would like to use awk to do the following calculation from the following snippet. input file C;2390 ;CV BOUILLOTTE 2L 2FACES NERVUREES ;1.00 ;3552612239004;13417 ;25 ;50 ; 12;50000 ; ; ... (3 Replies)
Discussion started by: iindie
3 Replies
Login or Register to Ask a Question