Appending string to match pattern (data processing)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending string to match pattern (data processing)
# 1  
Old 01-08-2010
Appending string to match pattern (data processing)

Hello
i have go the following result from performing 2 testing using the same file.
I have used unix script to extract the result because the files are many as shown below.

01_gravity.f.tcov 7 3 42.86
02_gravity.f.tcov 9 4 80.86
01_velocity.f.tcov 18 18 100.00
02_velocity.f.tcov 1 19 50.00
.
.
.


I will like to reagrange the data into colunms ie test 1 and test 2 results
(01_... 02_..) so that i can use gnuplot to analyse my reuslt in this format.

#File name Test1 Test 2
#=====================================================
gravity.f.tcov 7 3 42.86 9 4 80.86
velocity.f.tcov 18 18 100.00 1 19 50.00
.
.
.

Can any one help since am new to Unix scripting. Thank you
# 2  
Old 01-08-2010
perl:

Code:
while(<DATA>){
	chomp;
	my @tmp = split(" ",$_,2);
	my @t=split("_",$tmp[0]);
	push @{$hash{$t[1]}->{VAL}}, $tmp[1];
	$hash{$t[1]}->{SEQ}=$.;
}
foreach my $key(sort {$hash{$a}->{SEQ} <=> $hash{$b}->{SEQ}} keys %hash){
	print "$key @{$hash{$key}->{VAL}}\n";
}
__DATA__
01_gravity.f.tcov 7 3 42.86
02_gravity.f.tcov 9 4 80.86
01_velocity.f.tcov 18 18 100.00
02_velocity.f.tcov 1 19 50.00

# 3  
Old 01-08-2010
With awk:

Code:
awk '{sub(".*_","")}
$1 in a {s=$1;$1="";a[s]=a[s] $0; next}
{a[$1]=$0}
END{for(i in a){print a[i]}}
' file

# 4  
Old 01-08-2010
Than you all so much for your wonderful contributions
# 5  
Old 01-09-2010
Code:
awk -F [_\ ] '{a[$2]=a[$2]" "$3" "$4" "$5} END {for (i in a) {print i,a[i]}} ' urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern Match & Extract from a string

Hi, I have long string in 2nd field, as shown below: REF1 | CLESCLJSCSHSCSMSCSNSCSRSCUDSCUFSCU7SCV1SCWPSCXGPDBACAPA0DHDPDMESED6 REF2 | SBR4PCBFPCDRSCSCG3SCHEBSCKNSCKPSCLLSCMCZXTNPCVFPCV6P4KL0DMDSDSASEWG I have a group of fixed patterns which can occur in these long strings & only... (11 Replies)
Discussion started by: karumudi7
11 Replies

2. Shell Programming and Scripting

Processing 1 match string from grep at a time

hi all, i have a few log files with dates that are incorrrect (please don't ask me why). i need to add 2852 days, 16 hours, and 21 minutes (246471660 seconds) to each of these dates to correct them. i need to write to new "test2.txt" file that corrects the dates found by grep and yet have it... (4 Replies)
Discussion started by: cilantrocado
4 Replies

3. Shell Programming and Scripting

pattern match in a string

Hello, Please see below line code: #!/bin/ksh set -x /usr/bin/cat /home/temp |while read line do if ] then echo "matched" else echo "nope" fi done content of filr temp is as below (4 Replies)
Discussion started by: skhichi
4 Replies

4. Shell Programming and Scripting

Extract data from records that match pattern

Hi Guys, I have a file as follows: a b c 1 2 3 4 pp gg gh hh 1 2 fm 3 4 g h i j k l m 1 2 3 4 d e f g h j i k l 1 2 3 f 3 4 r t y u i o p d p re 1 2 3 f 4 t y w e q w r a s p a 1 2 3 4 I am trying to extract all the 2's from each row. 2 is just an example... (6 Replies)
Discussion started by: npatwardhan
6 Replies

5. Shell Programming and Scripting

Filename pattern match and appending pipe

Hi, I have a directory with around 100k files and files with varying sizes(10GB files to as low as 5KB). All the files are having pipe dilimited records. I need to append 7 pipes to the end of each record, in each file whose name contains _X3_ and need to append 10 pipes to the end of each... (3 Replies)
Discussion started by: nss280
3 Replies

6. Shell Programming and Scripting

Concatenating and appending string based on specific pattern match

Input #GEO-1-type-1-fwd-Initial 890 1519 OPKHIJEFVTEFVHIJEFVOPKHIJTOPKEFVHIJTEFVOPKOPKHIJHIJHIJTTOPKHIJHIJEFVEFVOPKHIJOPKHIJOPKEFVEFVOPKHIJHIJEFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #GEO-1-type-2-fwd-Terminal 1572 2030... (7 Replies)
Discussion started by: patrick87
7 Replies

7. Shell Programming and Scripting

Date Pattern Match (replacement string)

Hello, i am splitting files and sometimes the string of the pattern doesnt exist in the input file it starts for example with 00:00:01. So the output is completely desorganized, is there any way of putting a replacement string in the pattern so it will grab all the times from 00:**:** to first... (0 Replies)
Discussion started by: x-plicit78
0 Replies

8. Shell Programming and Scripting

Match pattern and replace with string

hi guys, insert into /*<new>*/abc_db.tbl_name this is should be replaced to insert into /*<new>*/${new}.tbl_name it should use '.' as delimiter and replace is there any way to do it using sed (6 Replies)
Discussion started by: sol_nov
6 Replies

9. Shell Programming and Scripting

pattern match url in string / PERL

Am trying to remove urls from text strings in PERL. I have the following but it does not seem to work: $remarks =~ s/www\.\s+\.com//gi; In English, I want to look for www. then I want to delete the www. and everything after it until I hit a space (but not including the space). It's not... (2 Replies)
Discussion started by: mrealty
2 Replies

10. UNIX for Advanced & Expert Users

how can awk match multi pattern in a string

Hi all, I need to category the processes in my system with awk. And for now, there are several command with similar name, so i have to match more than one pattern to pick it out. for instance: binrundb the string1, 2 & 3 may contain word, number, blank or "/". The "bin" should be ahead "rundb"... (5 Replies)
Discussion started by: sleepy_11
5 Replies
Login or Register to Ask a Question