Shell script to search through numbers and print the output

Suppose u have a file like

1 30
ABCSAAHSNJQJALBALMKAANKAMLAMALK
4562676268836826826868268468368282972982
2863923792102370179372012792701739729291
31 60
HSJBSHSLJSLDINEINSLSLNSLWONSLJWLU
6238286298182720710730723978219021019302
7582687167391937972138892368963883R89942

Another file have the
32
44
22
27

So output shud like while going throgh the first file at those particular numbers we have
32 S 2 5
44 I 2 3
22 K 3 7
27 M 7 2

explaining the selection logic (in 2 words or less) would help all of us!
also using the vB Codes when quoting the input files - could simplify the description.

So i acn simplify question
1 10
SSSSKSAGG
342456784324
335678899000

so question is find what is at
8 A 3 0
1 S 3 3

Thanks

Sorry, I don't understand it - must be me being 'thick-skulled'

Yah sorry may be i can more simplfy i apologise

say one file is
1 5 positions denotes from 1 to 5
ASERF
12424
21342
where 12424 is just below their ASERF
and 21432 is just below 12424
another file is like numbers
2
3
4
that is position number

So at position number 2 is S 2 1
similarly at position 3 is E 4 3
similiarly at position 4 is R 2 4

Try and adapt the following script :

awk '
NR==FNR {
   from = $1;
   to   = $2;
   for (i=1; i<=3; i++) {
      getline;
      for (j=from; j<=to; j++) {
         Values[j] = (i==1 && j==1 ? "" : Values[j] OFS) substr($0, j-from+1, 1);
      }
   }
   next;
}
{
   if ($1 in Values)
      print $1, Values[$1];
   else
      print $1, "Not Found";
}

' data_file numbers_file

data_file

1 30
ABCSAAHSNJQJALBALMKAANKAMLAMALK
4562676268836826826868268468368282972982
2863923792102370179372012792701739729291
31 60
HSJBSHSLJSLDINEINSLSLNSLWONSLJWLU
6238286298182720710730723978219021019302
7582687167391937972138892368963883R89942

numbers_file

1
2
22
30
31
32
44
60
99

Output

1 A 4 2
2  B 5 8
22  N 8 2
30  L 6 0
31  H 6 7
32  S 2 5
44  N 7 9
60  J 1 6
99 Not Found

Jean-Pierre.

Dear Pierre,
If u have input with space in between like

1 8
A G H H H U I O
22 33 44 55 32 53 4 55

Another file
2
4
6
So output will be like
2 G 33
4 H 55
6 U 53

Replace :

         Values[j] = (i==1 && j==1 ? "" : Values[j] OFS) substr($0, j-from+1, 1);

by :

         Values[j] = (i==1 && j==1 ? "" : Values[j] OFS) $(j-from+1);

Jean-Pierre.

If I understand correctly 8 should be in 2 :

awk 'NR == FNR { x[$1]; next }
NF { 
	for ( i in x ) 
		x = x ? x " " $i : $i 
	} END {
		for ( j in x )
			print j, x[j]
}' file2 file1
$ cat file1


1 8

A G H H H U I O
22 33 44 55 32 53 4 55


$ cat file2
2
4
6
$ nawk 'NR == FNR { x[$1]; next }
NF { 
for ( i in x ) 
x = x ? x " " $i : $i 
}END{
for ( j in x )
print j, x[j]
}' file2 file1
2 8 G 33
4 H 55
6 U 53

I'm not sure about the requirement,
but if the output should be really as shown:

$ nawk 'NR == FNR { x[$1]; next }
NF > 2 { 
for ( i in x ) 
x = x ? x " " $i : $i 
}END{
for ( j in x )
print j, x[j]
}' file2 file1
2 G 33
4 H 55
6 U 53

Use nawk or /usr/xpg4/bin/awk on Solaris.