Selecting rows with a specific criteria


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selecting rows with a specific criteria
# 1  
Old 07-19-2009
Selecting rows with a specific criteria

Hi,

I want a UNIX command that can filter out rows with certain criteria.
The file is tab deliminated. Row one is just a value. Basically what I want to do is select based on the name and character at the end (o). So lets lets say i want a row that has WashU and (o) then it would print into another file. Another thing is that the rows vary in size. Is this possible?

eg of the file:

Code:
YCR069W	 MIT_Spar_c89_2669 (o)  MIT_Smik_c1224_1803 (p)   MIT_Sbay_c91_2895 (o)   WashU_Scas_Contig720.92 (o)  
YCR071C	 MIT_Spar_c89_2672 (o)  MIT_Smik_c1224_1802 (o)   MIT_Sbay_c91_2899 (p)   WashU_Scas_Contig720.93 (p)   WashU_Skud_Contig1012.1 (o)  WashU_Sklu_Contig2173.3 (o)

So basically I want to select rows that have WashU at the start and (o) behind it.

Thanks

Phil

Last edited by vgersh99; 07-19-2009 at 07:04 PM.. Reason: code tags, PLEASE!
# 2  
Old 07-19-2009
Quote:
Originally Posted by phil_heath
...
So basically I want to select rows that have WashU at the start and (o) behind it.
...
I assume that "behind it" means "at the end of the line".

Code:
$ 
$ cat data.txt
YCR069W     MIT_Spar_c89_2669 (o)
WashU_Skud_Contig1012.1 (o)
MIT_Sbay_c91_2899 (p)
WashU_Scas_Contig720.93 (p)
$ 
$ awk '/^WashU.*\(o\)$/' data.txt
WashU_Skud_Contig1012.1 (o)
$

tyler_durden
# 3  
Old 07-20-2009
Tools You could also use grep and wildcards

Code:
cat testfile | grep "^WashU" | grep "(o)$"

display the file
grab lines that start with WashU
grab lines that end with (o)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Size Selecting rows

I have a rather convoluted script that I use to extract information from CSV files: sed '1d' PeakTable.txt | awk -F ',' '!/Ladder/{ if ( $4 > 430 && $4 < 490 && $5 > 45 ) print $2, $5; else print $2, 0 }' | awk '{a+=$2}END{for(i in a){print i, a}}' | sed 's/\(\)\(\) /\10\2 /' | sort | awk... (4 Replies)
Discussion started by: Xterra
4 Replies

2. Shell Programming and Scripting

Help with shell script: selecting rows that have the same values in two columns

Hello, everyone I am beginner for shell programming. I want to print all lines that have the same values in first two columns data: a b 1 2 a a 3 4 b b 5 6 a b 4 6 what I expected is : a a 3 4 b b 5 6 but I searched for one hour in... (2 Replies)
Discussion started by: nengcheng
2 Replies

3. Shell Programming and Scripting

Rows to Columns with match criteria

Hello Friends, I have a input file having hundreds of rows. I want them to translate in to columns if column 1 is same. Input data: zp06 xxx zp06 rrr zp06 hhh zp06 aaa zp06 ggg zp06 qwer zp06 ser zl11 old3 zl11 old4 zl11 old5 zl11 old6 zl11 old7 zm14 luri zm14 body zm14 ucp (9 Replies)
Discussion started by: suresh3566
9 Replies

4. Shell Programming and Scripting

pull out rows with specific criteria

Hi, I have a file with multiple columns and for column 5 I want to extract that row into another file if it is equal to or greater than a certain value. For example: FAR 4 5 7 LOP GAT 3 3 3 POL I want values that are greater than 5 for column 4. So the final file will look like... (1 Reply)
Discussion started by: phil_heath
1 Replies

5. UNIX for Dummies Questions & Answers

delete rows with a criteria

Hi, I would like to know how can I delete rows of a text file if from the 3rd column onwards there is only zeros? Thanks in advance (7 Replies)
Discussion started by: fadista
7 Replies

6. Shell Programming and Scripting

Selecting rows from a pipe delimited file based on condition

HI all, I have a simple challenge for you.. I have the following pipe delimited file 2345|98|1809||x|969|0 2345|98|0809||y|0|537 2345|97|9809||x|544|0 2345|97|0909||y|0|651 9685|98|7809||x|321|0 9685|98|7909||y|0|357 9685|98|7809||x|687|0 9685|98|0809||y|0|234 2315|98|0809||x|564|0 ... (2 Replies)
Discussion started by: nithins007
2 Replies

7. Shell Programming and Scripting

Selecting rows based on values in columns

Hi My pipe delimited .txt file contains rows with 10 columns. Can anyone advise how I output to file only those rows with the letters ‘ci' as the first 2 characters in the 3rd column ? Many thanks (4 Replies)
Discussion started by: malts18
4 Replies

8. UNIX for Dummies Questions & Answers

Help selecting some rows with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (2 Replies)
Discussion started by: capnino
2 Replies

9. Programming

selecting rows with specific IDs for downstream analysis

Hi, I'm working hard on SQL and I came across a hurdle I'm hoping you can help me out with. I have two tables table1 headers: chrom start end name score strand 11 9720685 9720721 U0 0 + 21 9721043 9721079 U0 0 - 1 9721093 9721129 U0 0 + 20 ... (2 Replies)
Discussion started by: labrazil
2 Replies

10. Shell Programming and Scripting

Selecting records from file on criteria.

Can I have 2 files as in input to the awk command? Situation is somewhat below, File A contains number & value delimited by a space. File B contains number as a part of a line. I am not supposed to retrieve more than 1 number from a line. If number from file B matches with number from... (7 Replies)
Discussion started by: videsh77
7 Replies
Login or Register to Ask a Question