"^" : Start of Line anchor
"." : Matches any single character except the newline character.
"*" : Matches the preceding character 0 or more times.app
test filespa
if_0 // no white space, no tab space if_1 // a tab space if_2 // two white space
command :code
$ grep "^if" test if_0
Conclusion :
^ is used to match the first column stringstring
test fileit
if_0 CROSS_COMPILE if_1 CROSS_COMPILE if_2 CROSS_COMPILE
command_1 :io
$ grep -rns "^if.*CROSS" test 1:if_0 CROSS_COMPILE
command_2 :test
$ grep -rns ".*if.*CROSS" test 1:if_0 CROSS_COMPILE 3: if_1 CROSS_COMPILE 4: if_2 CROSS_COMPILE
Conclusion :
For coding style, programmer place white or tab space in front of if.
If you want to find if as start, have to use ".*"sed
test filecoding
aaa1 aaa1 bbb2 bbb2 ccc3 ccc3
command_1 :file
$ grep "^bbb" test bbb2 bbb2
command_2 :
$ grep "^[^bbb]" test aaa1 aaa1 ccc3 ccc3