I need to match a pattern with grep, only if it starts at position 16. Let's suppose I want to match the string ' pattern' (starting with space).The following should matchbla bla bla bla patternwhereas following should not match, because the search pattern does not start at pos. 16:bla bla bla bla foo foo patternI have tried using this regular expressionegrep '.*\{15\} pattern'but this does not seem to work as desired.Can somebody please suggest a solution?
grep: match pattern on a particular position
grep;regular expression
I think what you are looking for is:grep -E '^.{15} pattern'This will be fine in most usage cases. However note that it won't 'match' just the pattern part, but everything before it will be included in the match too. You will see this by the highlighting of grep (if --color is given directly or has been included in a shell alias). Without colour, it will affect grep -o which prints just the matched part. Eg:$ echo 'bla bla bla bla pattern' | grep -Eo '^.{15}( pattern)'bla bla bla bla patternTo avoid this with GNU grep, you can use a perl expression with look behind. Eg:$ echo 'bla bla bla bla pattern' | grep -Po '(?<=^.{15}) pattern' patternThis 'matches' the pattern part only.