Awk For a Specific Term


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Awk For a Specific Term
# 1  
Old 07-26-2011
Awk For a Specific Term

I'm having trouble pulling specific ROWS out of a very large file. I've been using an awk command in unix that looks like this:

Code:
awk '{if ($16=="ACCEPTOR" ||  $16=="DONOR") print $0}'  file1 > file2

However, it is not selecting all of the rows which include either acceptor or donor in them. I imagine this is because there is an issue with what column those words are included in? Perhaps in some cases acceptor and donor are in column 15 or 17? Any help you can provide would be greatly appreciated - basically if the words acceptor or donor are in any rows I want them printed to the new file.

Thanks in advance!

Last edited by radoulov; 07-26-2011 at 03:59 PM.. Reason: Code tags!
# 2  
Old 07-26-2011
Why not grep?

Code:
grep -e "ACCEPTOR" -e "DONOR" <file1 >file2

# 3  
Old 07-26-2011
I have tried this and I get an empty file as the result Smilie
# 4  
Old 07-26-2011
Quote:
basically if the words acceptor or donor are in any rows I want them printed to the new file.
Code:
egrep 'ACCEPTOR|DONOR' Input > Output

# 5  
Old 07-26-2011
Still results in an empty file Smilie

Code:
egrep 'acceptor|donor' file1 > file2


Last edited by radoulov; 07-26-2011 at 04:00 PM.. Reason: Code tags!
# 6  
Old 07-26-2011
Why are you displaying the words in lower case?

Your original post had them in upper case:
Code:
awk '{if ($16=="ACCEPTOR" || $16=="DONOR") print $0}' file1 > file2

# 7  
Old 07-26-2011
haha yup, I just realized that.

It worked Smilie

Thank you so so so so so so very much.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies

2. Shell Programming and Scripting

awk to update specific value in file with match and add +1 to specific digit

I am trying to use awk to match the NM_ in file with $1 of id which is tab-delimited. The NM_ will always be in the line of file that starts with > and be after the second _. When there is a match between each NM_ and id, then the value of $2 in id is substituted or used to update the NM_. Each NM_... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

4. Shell Programming and Scripting

awk based script to print the "mode(statistics term)" for each column in a data file

Hi All, Thanks all for the continued support so far. Today, I need to find the most occurring string/number(also called mode in statistics terminology) for each column in a data file (.csv type). For one column of data(1.txt) like below Sample 1 2 2 3 4 1 1 1 2 I can find the mode... (6 Replies)
Discussion started by: ks_reddy
6 Replies

5. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

6. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

7. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

8. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

9. Shell Programming and Scripting

Search term and output term in desired field

Hi All, I have an input_file below and i would like to use Perl to search for the term "aaa" and output the 3rd term in the same row as "aaa".For Example, i want to search for the term "ddd" and would want the code to ouput the 3rd term in the same row which is "fff". Can somebody help ? ... (28 Replies)
Discussion started by: Raynon
28 Replies

10. Programming

Create a Term & Run chars on this Term

hi floks ! i'd like to know how can i transmete a character or a string from my source code to a term and make it interpret or un by the shell wich is running in my term. I'd like to create a Term from my code (and get its file descriptor) and then transmete each char typed on the keyboard to... (1 Reply)
Discussion started by: the_tical
1 Replies
Login or Register to Ask a Question