[Solved] Search for specific characters in specific positions of line


To search for “foo” at position 42:

egrep '^.{42}foo'

You can run a command like this multiple times on your input:

egrep '^.{42}foo' inputfile.txt > lineswithfoo.txt
egrep '^.{42}bar' inputfile.txt > lineswithbar.txt
...

or as a loop:

for pattern in foo bar qux; do
  egrep "^.{42}$pattern" inputfile.txt > lineswith$pattern.txt
done

solved Search for specific characters in specific positions of line