Hi awk gurus,
my wife has asked me if I could program something for her, but my last experience of working with sed and awk dates back to like 1995.
Perl would be another option I guess to accomplish this task but I have a feeling it might be even easier in awk.
But let me explain the problem:
I have 2 files, and based on specific information in file1 I have to change the contents of file2.
Here is how the files look like:
file1:
[tt] 5 Val HG1# 47 Ile HB 2.8 4.5
7 Val HB 8 Ser HB2 2.8 4.5
7 Val HG2# 8 Ser Hn 2.8 4.5
8 Ser HA 48 Ile HD1# 2.8 6.0
[/tt]
file2:
[tt]! residue 1 Met , NOEs forward in sequence
! residue 2 Ala , NOEs forward in sequence
! residue 3 Ser , NOEs forward in sequence
! residue 4 Gly , NOEs forward in sequence
assi (resi 4 and name HA1 ) (resi 5 and name HN ) 2.80 2.80 0.00
assi (resi 4 and name HA2 ) (resi 5 and name HN ) 2.80 2.80 0.00
assi (resi 4 and name HA2 ) (resi 6 and name HN ) 4.50 4.50 0.00
! residue 5 Val , NOEs forward in sequence
assi (resi 5 and name HN ) (resi 6 and name HN ) 2.80 2.80 0.00
assi (resi 5 and name HN ) (resi 6 and name HA ) 4.50 4.50 0.00
assi (resi 5 and name HN ) (resi 6 and name HB# ) 4.50 4.50 0.00[/tt]
Ok, I can use the default FS and get nice fields.
The information in file1 for finding matching lines in file2 are fields
1,3,4 and 6.
In file2 we are ignoring all lines starting with a ! and we only look at fields
3,6,9 and 12 to dinf matches.
Now I want to search for all lines where
[tt]
field 1(file1) matches field3(file2)
field 3(file1) matches field6(file2)
field 4(file1) matches field9(file2)
field 6(file1) matches field12(file2)
[/tt]
In those matching lines I need to replace the contents of
field 13 and 14 in file2 with the value of field 8 of file1.
Optional: additional checking that field 13 and 14 of file2
should be equal to field 8 of file1.
Ok, I guess that was confusing enough but I tried to explain
as well as I could.
I have tried several approaches but failed misarably :-(
Maybe someone with more programming experience could get me
started? Currently my wife is doing all this by hand which
takes hours - file1 can be several hunderd lines and file2
1000+ lines.
Thanks alot in advance for all hints - if you get me started
I guess I might be able to figure out the rest by myself ;-)
Zodiak
my wife has asked me if I could program something for her, but my last experience of working with sed and awk dates back to like 1995.
Perl would be another option I guess to accomplish this task but I have a feeling it might be even easier in awk.
But let me explain the problem:
I have 2 files, and based on specific information in file1 I have to change the contents of file2.
Here is how the files look like:
file1:
[tt] 5 Val HG1# 47 Ile HB 2.8 4.5
7 Val HB 8 Ser HB2 2.8 4.5
7 Val HG2# 8 Ser Hn 2.8 4.5
8 Ser HA 48 Ile HD1# 2.8 6.0
[/tt]
file2:
[tt]! residue 1 Met , NOEs forward in sequence
! residue 2 Ala , NOEs forward in sequence
! residue 3 Ser , NOEs forward in sequence
! residue 4 Gly , NOEs forward in sequence
assi (resi 4 and name HA1 ) (resi 5 and name HN ) 2.80 2.80 0.00
assi (resi 4 and name HA2 ) (resi 5 and name HN ) 2.80 2.80 0.00
assi (resi 4 and name HA2 ) (resi 6 and name HN ) 4.50 4.50 0.00
! residue 5 Val , NOEs forward in sequence
assi (resi 5 and name HN ) (resi 6 and name HN ) 2.80 2.80 0.00
assi (resi 5 and name HN ) (resi 6 and name HA ) 4.50 4.50 0.00
assi (resi 5 and name HN ) (resi 6 and name HB# ) 4.50 4.50 0.00[/tt]
Ok, I can use the default FS and get nice fields.
The information in file1 for finding matching lines in file2 are fields
1,3,4 and 6.
In file2 we are ignoring all lines starting with a ! and we only look at fields
3,6,9 and 12 to dinf matches.
Now I want to search for all lines where
[tt]
field 1(file1) matches field3(file2)
field 3(file1) matches field6(file2)
field 4(file1) matches field9(file2)
field 6(file1) matches field12(file2)
[/tt]
In those matching lines I need to replace the contents of
field 13 and 14 in file2 with the value of field 8 of file1.
Optional: additional checking that field 13 and 14 of file2
should be equal to field 8 of file1.
Ok, I guess that was confusing enough but I tried to explain
as well as I could.
I have tried several approaches but failed misarably :-(
Maybe someone with more programming experience could get me
started? Currently my wife is doing all this by hand which
takes hours - file1 can be several hunderd lines and file2
1000+ lines.
Thanks alot in advance for all hints - if you get me started
I guess I might be able to figure out the rest by myself ;-)
Zodiak