Search for multiple strings in specific position

Hi,

I need to search for some strings in specific positions in a file.

If the strings: "foo1", "foo2" or "foo3" is on position 266 or position 288 in a file i want the whole line printed.

Any idea how to do it?

you can use grep -x for finding specific string in file.

But i cannot specify the position then?

The strings may be at more places but they are only interesting if they are in this positions.

With some hardwiring, but... something to start with:

nawk -v str='foo1|foo2|foo3' 'substr($0, 266, 4) ~ str || substr($0, 288, 4) ~ str' myFile

:b:

Thanks, thanks & thanks again!

It solved my problem.

:b:

a more generic solution:

nawk -v str='foo1 foo2 foo3' -v pos='266 288' -f hugo.awk myFile

hugo.awk:

BEGIN {
   split(str, strA, FS)
   split(pos, posA, FS)
}
{
   for(strI=1; strI in strA; strI++)
      for(posI=1; posI in posA; posI++)
        if ( posA[posI] == match($0, strA[strI]) ) {
           print
           next
        }
}