3/17/2023 0 Comments Grep linux commandFollowing picture show the example for the line numbers. This will help user to go the line when user open the file in vi editer to know nearby logs. grep display with Line numbers: grep with option -n print the line number where the search text is present.Following picture show the example where we can see error (small letter) appeared two time in the log file an Error (with captil ‘E’) appeared 22 time in the event-log file. count option is case sensitive, be sure about the actual search string. GREP will by default display any lines in a file that contain the expression. This is useful when we want to know how many time one particular error happen in the log file. The basic usage of the command is : grep options expression filename. grep with count: grep with option -c search and provide the number of count for a text or string appeared in the file.For example if you want to search error in a file, you can put error or Error in search text will ingore and provide all related matching lines. grep with ingore case: grep with option -i search for the given text and igore the upper/lower case.-o : Print only the matched parts of a matching line, with each such part on a separate output line.-E : Treats pattern as an extended regular expression.-f file : Takes patterns from file, one per line.-e exp : Specifies expression with this option.-v : This prints out all the lines that do not matches the pattern.-n : Display the matched lines and their line numbers. -i : Ignores upper/lower case for matching.-h : Display the matched lines, but do not display the filenames.-c : This prints a count of the lines that match the pattern.For example, search for file1.txt that matches the string/pattern linux with the following command: grep -o linux file1. You can print only matching patterns using the -o option. grep does not work in the Windows environment By default, grep command prints the entire line which matches a pattern.grep user requires read/write permissions to access the desired files and directories.grep requires access to a terminal/command line.egrep, and fgrep are other similar tools.The grep command is handy tool for searching known text or string through large log files.When grep finds a match, it prints the line with the result.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |