Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transforming data

Status
Not open for further replies.

Simmy

Technical User
Sep 7, 2002
27
GB
Hello,
I have a serious problem and I think I can solve it with AWK but I don't know how.

I have a lot of data that looks like this:
graph 12345
using 12345
data 1234

and I want to transform it like this:
each letter of the word becomes a record,
in the record the letter has three letters left and three letters right context so: -,-,-,g,r,a,p (- since there is no context)
and at the end of the record I want the number that corresponds to the letter so the entire record is:
-,-,-,g,r,a,p,1
and the next records:
-,-,g,r,a,p,h,2
-,g,r,a,p,h,-,3
g,r,a,p,h,-,-,4
r,a,p,h,-,-,-,5

I know this isn't something you can answer rightaway but any help is welcome
 
Does this do what you want?
Code:
{
  l1 = length($1)
  a = "---" $1 "---"
  for (j=1;j<=l1;j++) {
    for (k=j;k<=l1+j+1;k++) {
      printf substr(a,k,1) &quot;,&quot;
    }
    print substr($2,j,1)
  }
}
CaKiwi
 
I think I got the second for statement wrong. It should be
[tt]
{
l1 = length($1)
a = &quot;---&quot; $1 &quot;---&quot;
for (j=1;j<=l1;j++) {
for (k=j;k<=j+6;k++) {
printf substr(a,k,1) &quot;,&quot;
}
print substr($2,j,1)
}
}
[/tt] CaKiwi
 
I don't really know why but it works allright.
Thanks a lot!
Simmy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top