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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sliding window problem

Status
Not open for further replies.

LovecraftHP

Programmer
Dec 3, 2002
15
CN
Let me first give an example of what I would like to do:

I have an input file consisting of a number of records, each record consisting of 2 fields eg

list lIst
screen skri.n

I want to be able to shift the focus letter of the first field, along with its context (eg 3 letters to the right, 3 letters to the left), as the letters of the second word are processed. Kind of like a window sliding over the word. So the output in this case would be

-,-,-,l,i,s,t,l
-,-,l,i,s,t,-,I
-,l,i,s,t,-,-,s
l,i,s,t,-,-,-,t
-,-,-,s,c,r,e,s
-,-,s,c,r,e,e,k
-,s,c,r,e,e,n,r
s,c,r,e,e,n,-,i
c,r,e,e,n,-,-,.
r,e,e,n,-,-,-,n

My main problem is that I can't seem to shift the focus as the second field is processed. I don't know how to make the window "slide".

Any help would be greatly appreciated...
 
I'm not sure if I understand the exact criteria you want but this awk program produces the output you posted.

{
a = "---" $1 "---"
k = length($2)
for (j1=1;j1<=k;j1++) {
for (j2=j1;j2<=j1+6;j2++) printf substr(a,j2,1) &quot;,&quot;
print substr($2,j1,1)
}
}
CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top