awk '
function check( cn, i, j, ln) {
# local variables:
# cn sequence column number within line
# i loop control
# j loop control
# ln sequence line number
# Loop through the list of entries from the position file...
for(i = 1; i <= sc; i++) {
if(f[2] != id[i]) continue # Different Id? Then go on.
# Calculate column and line corresponding to position.
cn = (pos[i] - 1) % 60 + 1
ln = int((pos[i] + 59) / 60) - 1
if(ln > lc) continue # Line out of range? Then go on.
if(old[i] == substr(line[ln], cn, 1)) {
# Original matches... print the updated record. First
# print the updated header line.
printf("%s|%s|%s%s%s %s", f[1], f[2], old[i], pos[i],
new[i], f[3])
for(j = 4; j <=fn; j++) printf("|%s", f[j])
printf("\n")
# Print sequence lines before the line containing the
# updated position.
for(j = 0; j < ln; j++) print line[j]
# Print the line with the modified position.
printf("%s%s%s\n", substr(line[ln], 1, cn - 1), new[i],
substr(line[ln], cn + 1))
# Print sequence lines after the line containing the
# updated position.
for(j = ln + 1; j < lc; j++) print line[j]
}
}
# Reeet to process next record.
gather = lc = 0
}
FNR == NR && NR > 1 { # Read lines from position file (skipping header).
id[++sc] = $1 # Id for input line sc
sid[id[sc]] # List of known Ids
old[sc] = $2 # Original letter for input line sc
pos[sc] = $3 # Position for input line sc
new[sc] = $4 # Replacement letter for input line sc
next}
/^>sp/ {# This is the 1st line of a new record...
if(gather) check() # Process previous record.
nf = split($0, f, /[|]/)# Split 1st line of this record into fields.
# If the Id in this line is in our list, gather the rest of this record.
if(f[2] in sid) gather = 1
next
}
gather {line[lc++] = $0
}
END { # Process the last record...
if(gather) check()
}' position sequence
If you want to try this on a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.
This User Gave Thanks to Don Cragun For This Post:
Hi,
Long list of Input file1 content:
1285_t
4860_i
4817_v
8288_c
9626_a
.
.
.
Long list of Input file2 content:
1285_t chris germany
8288_c steve england
9626_a dave swiss
9260_s stephanie denmark
.
.
. (14 Replies)
Hi,
im able to search for string in a file (ex: grep -w "$a" input.txt). but i have to search for the uppercase of a string in a file where upper case of the file content matches something like below.
where upper("$a")== converted to upper case string in (input.txt)
can someone please provide... (5 Replies)
Good afternoon all,
I want to ask how to change some letter in my file with other letter in spesific line
eg.
data.txt
1
1
1
0
0
0
0
for example i want to change the 4th line with character 1.
How could I do it by SED or AWK.
I have tried to run this code but actually did not... (3 Replies)
Hi,
I need to replace, as the title says, the first letter of each line (when it's not a number) by the same letter, but capital.
For instance :
hello
Who
123pass
Would become :
Hello
Who
123pass
Is there a way with sed to do that ? Or other unix command ?
Thank you :) (7 Replies)
I have a pbd file, which has the following format:
TITLE Protein X
MODEL 1
ATOM 1 N PRO 24 45.220 71.410 43.810 1.00 0.00
ATOM 2 H1 PRO 24 45.800 71.310 42.000 1.00 0.00
TER
ENDMDL
Column 22 is the chain... (5 Replies)