![grep linux grep linux](https://4.bp.blogspot.com/-dGHeNiu17vk/Vpu5YqufpNI/AAAAAAAAEoI/lbcxbCTpcog/s1600/10%2BExample%2Bof%2BGREP%2Bcommand%2Bin%2BUNIX.png)
Grep <- will match the strings "1", "2", "a3bc", but it won't match "a" or "house" Grep <- will match the strings "hello" and "Hello" The can be used to match a character from a list. Grep 'abcd\(mm\)\?xyz' <- will match 'abcdmmxyz' and 'abcdxyz' So, in combination with the ? character, it is possible to specify optional substring. Ls | grep '\.jso\?' <- will match files which contains '.js' or '.jso'Īn expression surrounded by escaped parentheses is treated by as a single character. Grep 'abc\?' <- will match 'abc' and 'ab' The ? character match any string in which the character before an escaped ? is present one or zero times. Grep 'somefile.ext' will match files like these: Ls | grep '\.js' <- this will return all files which contains the '.js' string as part of their name. If we want to match the dot in the file name, we must escape the dot in the grep statement in this way: To find all lines which contains the string 'image.gif', the dot character must be escaped:Įxecuting ls | grep '.js' will return all files, because in this case, the dot is a wildcard that will match any character. To escape a special character (grep won't interpret its special meaning) the \ character must be used before the target character. The boy is going to the town (Match on: he boy. > This will match any string which contains a substring which has an 'h' followed by 0 or more character of any kind, and then and 'h'. The * wildcard can be used to specify that the character before it can be 0 or more times repeated. > This will return all lines from the file 'some-file' which contains a string with the form 'function. wildcard can be used to specify that any character (just one) will match the searched string if everything else match. > This will return all files which contains the string 'some-string' in their names > This will return all lines of the file named 'some-file' which contains the string 'some-string'. Grep searches strings/patterns inside other strings/text.