Extract specific data content from a long list of data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract specific data content from a long list of data
# 8  
Old 12-09-2009
Code:
$ awk 'BEGIN{RS="";FS="\n"}
/Data name/ { split($1,a," ")
     for (i=2;i<=NF;i++) 
         {if (($i~/forward/)||($i~/reverse/)) 
              { split($i,b," "); print a[3],b[3],b[4]}}
     {printf "\n"}}'  urfile

ABC001 10 100
ABC001 15 200
ABC001 50 500

XFG110 50 100
XFG110 50 90

ABC010 150 190

# 9  
Old 12-09-2009
Hi rdcwayx, your code is worked fine too. Just it lack of put a ";" before the for.
I already edited it for you Smilie
Thanks a lot.

Code:
$ awk 'BEGIN{RS="";FS="\n"}
/Data name/ { split($1,a," ") ;
     for (i=2;i<=NF;i++) 
         {if (($i~/forward/)||($i~/reverse/)) 
              { split($i,b," "); print a[3],b[3],b[4]}}
     {printf "\n"}}'  urfile

ABC001 10 100
ABC001 15 200
ABC001 50 500

XFG110 50 100
XFG110 50 90

ABC010 150 190

# 10  
Old 12-10-2009
Interesting, I needn't the ; in my system.

Anyway, that's good to hear the problem is fixed.
# 11  
Old 12-14-2009
Code:
my $flag=0;
my $name;
while(<DATA>){
	if(/^Data name:\s*(.*)/){
		$name = $1;
	}
	elsif(/Start_time End_time/){
		$flag=1;
	}
	elsif(/^\s*$/){
		print "\n";
		$flag=0;		
	}
	else{
		if($flag eq 1){
			my @tmp = split;
			print $name," ",$tmp[2]," ",$tmp[3],"\n";
		}
	}
}
__DATA__
Data name: ABC001
Data length: 1000
Detail info
Data Direction Start_time End_time Length
1 forward 10 100 90       
1 forward 15 200 185
2 reverse 50 500 450

Data name: XFG110
Data length: 100
Detail info
Data Direction Start_time End_time Length
1 forward 50 100 50       
2 reverse 50 90 40

Data name: ABC010
Data length: 200
Detail info
Data Direction Start_time End_time Length
1 forward 150 190 40

# 12  
Old 12-14-2009
thanks summer, I trying your suggestion now Smilie
Thanks first ^^
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How-To Extract specific data from a file.

data.txt has several information like the below.. <SERVER>:WEB:MYDOM01:/tmp/cong/MYDOM01,/tmp/app/MYDOM01 <WEBER>:CANES:https-web01,https-web02:/web/apps/https-web01/config <SERVER>:WEB:MYDOM07:/tmp/cong/MYDOM07,/tmp/app/MYDOM07... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

How to extract specific data?

Bash scripting beginner here... I have many folders, each folder representing one subject. Not all subjects have all the required files, so I need to somehow cycle through all the data and then extract the data only from subjects who have no files missing. I tried to output the ls command, but... (4 Replies)
Discussion started by: LeftoverStew
4 Replies

3. HP-UX

How to extract data for a specific process from ovpa?

Hi Friends, One question. Supposed I want to extract data only for process named "sqlplus" how can I do it. Any suggestions? I don't want all the data as it is not useful to me e.g.. Command I use is given below extract -xp -p -r repfile -b"03/15/13 7:00 PM" -e"03/15/13 09:30 PM" -f... (1 Reply)
Discussion started by: kunwar
1 Replies

4. Shell Programming and Scripting

Extract specific data and change its arrangment

Input: HS04636 PROGRAM source 836 7001 + ID=g1 HS04636 PROGRAM beginner 836 7001 + ID=g1.t1;Parent=g1 HS04636 PROGRAM position 836 836 + Parent=g1.t1 HS04636 PROGRAM type 836 1017 + Parent=g1.t1 HS04636 ... (2 Replies)
Discussion started by: patrick87
2 Replies

5. Shell Programming and Scripting

Extract specific content from data and rename its header problem asking

Input file 1: >pattern_5 GAATTCGTTCATGTAGGTTGASDASFGDSGRTYRYGHDGSDFGSDGGDSGSDGSDFGSDF ATTTAATTATGATTCATACGTCATATGTTATTATTCAATCGTATAAAATTATGTGACCTT SDFSDGSDFKSDAFLKJASLFJASKLFSJAKJFHASJKFHASJKFHASJKFHSJAKFHAW >pattern_1 AAGTCTTAAGATATCACCGTCGATTAGGTTTATACAGCTTTTGTGTTATTTAAATTTGAC... (10 Replies)
Discussion started by: patrick87
10 Replies

6. Shell Programming and Scripting

Extract specific read from a data

Input file: #abc_1 SAASFASFGGDSGDSGDSGSDGSDGSDGSDGSDGSDGSDGDS Output file: FASFGGDSGDS I just want to print out the read from position 5 until position 15 from the data. Below is the code that I just try but it is failed to get my desired output: grep -v '#' input_file | awk... (5 Replies)
Discussion started by: patrick87
5 Replies

7. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

Extract all the content after a specific data

My input: >seq_1 DSASSTRRARRRRTPRTPSLRSRRSDVTCS >seq_3 RMRLRRWRKSCSERS*RRSN >seq_8 RTTGLSERPRLPTTASRSISSRWTR >seq_10 NELPLEKGSLDSISIE >seq_9 PNQGDAREPQAHLPRRQGPRDRPLQAYA+ QVQHRRHDHSRTQH*LCRRRQREDCDRLHR >seq_4 DRGKGQAGCRRPQEGEALVRRCS>seq_6 FA*GLAAQDGEA*SGRG My output: Extract all... (22 Replies)
Discussion started by: patrick87
22 Replies

9. Shell Programming and Scripting

Shell script or command help to extract specific contents from a long list of content

Hi, I got a long list of contents: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF... (2 Replies)
Discussion started by: patrick87
2 Replies

10. Shell Programming and Scripting

Extract data into file with specific field specs

:confused: I have a tab delimited file that I need to extract data from and into a file with specific field specs. Each field has to be a certain amount of characters. So, the name field (from delimited file) might have only 15 characters but needs to be 25 (in new file) so I need to insert spaces... (5 Replies)
Discussion started by: criddel
5 Replies
Login or Register to Ask a Question