Search code examples
regexshellgrepksh

What does `grep -E "xyz\.(.+)\.abc"` do in korn shell?


I have seen this piece of code in a ksh script. Wondering what it does?

grep -E "xyz\.(.+)\.abc"

Solution

  • It has nothing to do with Korn shell. grep is a tool for matching regular expressions and the -E option specifies that extended regex should be used instead of the default basic regex. For more information about that read Basic vs Extended Regular Expressions or run man grep, man regex

    So grep -E "xyz\.(.+)\.abc" will find a line containing the string xyz. followed by anything then .abc in the input. Since there's no input file specified, it'll read the input from stdin