Hi All, I am new to unix and is trying with a few things. I am encountering the below error when executing a command like grep -B 2 'string' sample.txt grep: illegal option -- B usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list... [-f pattern_file...] [file...] usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...] -f pattern_file... [file...] usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...] Can anybody tell me the reason for this error. Thanks in advance and wishing you all a very happy new year.
grep -B 2 ... should work. Worked on my Mac [terminal] using darwin. did you check the man pages on your system? Q...
Unlike Mac/PC, Unix is always case sensitive. This is also true for directory name, database names, tables names, etc..
Partial man page for grep: -B NUM, --before-context=NUM Print NUM lines of leading context before matching lines. Places a line containing -- between contiguous groups of matches. -C NUM, --context=NUM Print NUM lines of output context. Places a line containing -- between contiguous groups of matches. -b, --byte-offset Print the byte offset within the input file before each line of output. : Code (markup): I took case sensitivity into consideration. Q...
grep -B is not working for me in only one server. On other servers it is working fine. So i doubt if we have to install anything else for this option to work. Anybody has any idea.