Extracting specific rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting specific rows
# 1  
Old 08-25-2011
Extracting specific rows

Hi all.....

I have a file which contains large data...like
Quote:
IOJN HIO IHFN SDHNN KHUH
UIH BHU FHHFIHFL LF'
UIHY HFJKDHY FNNOL
OIY H D FHKLJ'S
PUJF JLDSFJ';O[0-OP OI
HUIH SDH JIO [ASDCG GFF ]
GBGYG HU BXJBCTEWFOU CHXJK
pixel 2255 CD PNT A 276 63.306 68.558 115.900 1.00 38.11 C
pixel 2256 OXT PGT A 276 65.070 72.831 115.339 1.00 46.27 O

pixel 2257 CD PSD A 277 63.306 68.558 115.900 1.00 38.11 C
pixel 2258 OXT PJG A 277 65.070 72.831 115.339 1.00 46.27 O

pixel 2259 CD PLO A 278 63.306 68.558 115.900 1.00 38.11 C
pixel 2260 OXT POK A 279 65.070 72.831 115.339 1.00 46.27 O

pixel 2261 CD ASD A 276 63.306 68.558 115.900 1.00 38.11 C
pixel 2262 OXT FEO A 276 65.070 72.831 115.339 1.00 46.27 O

pixel 2263 CD WDG A 276 63.306 68.558 115.900 1.00 38.11 C
pixel 2264 OXT JIO A 276 65.070 72.831 115.339 1.00 46.27 O
TER

JFOCJS AWD ERW
FAS F FRES
ASD CGRE
AWFC GTRGD
ASFC HRSH
ERY
UFJ JYBFGD GREG


I want to print the rows starting from "pixel" till the file read the letter "TER" into a new output file....

can anyone plz help in doing this ??
# 2  
Old 08-25-2011
Code:
$ sed -n '/[pP]ixel/,/TER/p' inputfile > outputfile

# 3  
Old 08-25-2011
???
Code:
grep '^pixel'

# 4  
Old 08-25-2011
If you have Ruby(1.9+)
Code:
$ ruby -ne 'print if /^pixel/../^TER/' file

# 5  
Old 08-25-2011
Hi kurumi,

ur code works well......but the problem is that most of my file contains multiple TER like:


Quote:
OJN HIO IHFN SDHNN KHUH
UIH BHU FHHFIHFL LF'
UIHY HFJKDHY FNNOL
OIY H D FHKLJ'S
PUJF JLDSFJ';O[0-OP OI
HUIH SDH JIO [ASDCG GFF ]
GBGYG HU BXJBCTEWFOU CHXJK
pixel 2255 CD PNT A276 63.306 68.558 115.900 1.00 38.11 C
pixel 2256 OXT PGT A 276 65.070 72.831 115.339 1.00 46.27 O
pixel 2257 CD PSD A 277 63.306 68.558 115.900 1.00 38.11 C
pixel 2258 OXT PJG A 277 65.070 72.831 115.339 1.00 46.27 O
TER 2344 fwe lkjn A fj;90- 09 0 4564 098 676 56.876 567.897
pixel 2259 CD PLO B 278 63.306 68.558 115.900 1.00 38.11 C
pixel 2260 OXT POK B 279 65.070 72.831 115.339 1.00 46.27 O
pixel 2261 CD ASD B 276 63.306 68.558 115.900 1.00 38.11 C
pixel 2262 OXT FEO B 276 65.070 72.831 115.339 1.00 46.27 O
pixel 2263 CD WDG B 276 63.306 68.558 115.900 1.00 38.11 C
pixel 2264 OXT JIO B 276 65.070 72.831 115.339 1.00 46.27 O
TER
JFOCJS AWD ERW
FAS F FRES
ASD CGRE
AWFC GTRGD
ASFC HRSH
ERY
UFJ JYBFGD GREG
And I want to extract lines containing ATOM only till first TER.... i.e, in the above case all lines containing A.....as soon as A changes to B, the code must terminate there.
I cant use character "A"as marker....because other files may contain any other alphabet instead of A like "D" and after first TER, "E" rows starts.

Last edited by CAch; 08-25-2011 at 05:01 PM..
# 6  
Old 08-25-2011
Code:
$ ruby -ne 'print if /^pixel/; exit if /^TER/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

2. Shell Programming and Scripting

Extracting rows and columns in a matrix based on condition

Hi I have a matrix with n rows and m columns like below example. i want to extract all the pairs with values <200. Input A B C D A 100 206 51 300 B 206 100 72 48 C 351 22 100 198 D 13 989 150 100 Output format A,A:200 A,C:51 B,B:100... (2 Replies)
Discussion started by: anurupa777
2 Replies

3. UNIX for Dummies Questions & Answers

Extracting rows from a text file if the value of a column falls between a certain range

Hi, I have a file that looks like the following: 10 100080417 rs7915867 ILMN_1343295 12 6243093 7747537 10 100190264 rs2296431 ILMN_1343295 12 6643093 6647537 10 100719451 SNP94374 ILMN_1343295 12 6688093 7599537 ... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

extracting number of rows

if > wc -l data.txt > 100 (meaning there are 100 rows) i want to assgn 100 as n so that if i do >echo n it would give me 100 Thanks (5 Replies)
Discussion started by: johnkim0806
5 Replies

5. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the values of two columns (given ranges)

Hi, I have a tab delimited text file with multiple columns. The second and third columns include numbers that have not been sorted. I want to extract rows where the second column includes a value between -0.01 and 0.01 (including both numbers) and the first third column includes a value between... (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Extracting rows with a certain column

Hi, I want to extract rows that have specific characters at a certain column. It might be best to show you my problem. So my tab delimited file looks like this: YPR161C 10 16 864445 866418 - Verified 3.558 YOL138C 6 15 61325 65350 - Verified 0.6... (1 Reply)
Discussion started by: phil_heath
1 Replies

7. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on numerical values of a column

I have a text file where the second column is a list of numbers going from small to large. I want to extract the rows where the second column is smaller than or equal to 0.0001. My input: rs10082730 9e-08 12 46002702 rs2544081 1e-07 12 46015487 rs1425136 1e-06 7 35396742 rs2712590... (1 Reply)
Discussion started by: evelibertine
1 Replies

8. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the first column

I have a tab delimited text file where the first column can take on three different values : 100, 150, 250. I want to extract all the rows where the first column is 100 and put them into a separate text file and so on. This is what my text file looks like now: 100 rs3794811 0.01 0.3434 100... (1 Reply)
Discussion started by: evelibertine
1 Replies

9. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the first column

I have a tab delimited text file where the first column can take on three different values : 100, 150, 250. I want to extract all the rows where the first column is 100 and put them into a separate text file and so on. This is what my text file looks like now: 100 rs3794811 0.01 0.3434... (1 Reply)
Discussion started by: evelibertine
1 Replies

10. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies
Login or Register to Ask a Question