I hope you can help me figure this out. I need to print a record which contains the contents of a config file. The contents of the config file should be found within the 21st and the 30th position of the fixed width reference file.
If your reference file always looks like this (that is, the fields are surrounded by ample whitespace AND the search patterns will not appear somewhere else on the line), itkamarajs solution is probably the easiest and fastest.
where it is not possible to match for a word and the search pattern is distinguishable only by the position on the line you will have to do a bit more, for instance a shell loop:
#! /bin/ksh
typeset PATTERN=""
cat /path/to/config.file |\
while read PATTERN ; do
grep '^.\{20\}'"${PATTERN}" /path/to/reference.file
done
exit 0
This will "anchor" the pattern to character position 21 in the line by searching for "20 characters followed by $PATTERN".
If the search patterns contain regexp metacharacters (like "", ".", etc.) you might have to take evn more precautions by escaping these (precede them with a backslash, i.e. "" -> "\*").
Taking all these precautions will not hurt, even if they are unnecessary, but they might slow down the process, soanalyze your data carefully if they are necessary or not.