tag:blogger.com,1999:blog-8712770457197348465.post5655899376803410522..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: 10 examples of grep command in UNIX and Linuxjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger40125tag:blogger.com,1999:blog-8712770457197348465.post-6633439881148786662022-12-22T21:49:12.413-08:002022-12-22T21:49:12.413-08:00Thanks a lotThanks a lotAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-21292031299135194062016-02-06T02:41:20.733-08:002016-02-06T02:41:20.733-08:00@Sachin, why not just grep with the date format yo...@Sachin, why not just grep with the date format you are using e.g. if you are using DDMMYYY just use grep '01022016' abc.log.<br />javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66721157194451621312016-01-27T23:49:10.620-08:002016-01-27T23:49:10.620-08:00Can Anyone help me to capture date wise log using ...Can Anyone help me to capture date wise log using grep command with example Anonymoushttps://www.blogger.com/profile/07496558748226156506noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26676646090157569192015-09-28T21:11:07.965-07:002015-09-28T21:11:07.965-07:00One of the useful grep command option which I woul...One of the useful grep command option which I would like to add is "grep -o" where o is for only matching and shows the part of line which matches the given pattern. One example of this to print status code from Apache server's log as shown below :<br /><br />$ grep -o " [0-9]{3} " /var/log/apache2/access.log<br /> 503<br /> 404 <br /> 404 <br /> 200 <br /> 200 <br /> 200Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56100655237542821372014-12-12T05:42:48.990-08:002014-12-12T05:42:48.990-08:00You can avoid piping grep into another grep when &...You can avoid piping grep into another grep when 'grep' itself is part of the output string. Consider following example:<br /><br />ps -ef | grep 'HTTP' | grep -v 'grep'<br /><br />You can achieve same effect by using regular expression with grep command like this <br /><br />ps -ef | grep '[H]TTP'Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7242467676387007962014-03-25T20:16:07.582-07:002014-03-25T20:16:07.582-07:00Well Said @Steven. In fact I am also big fan of eg...Well Said @Steven. In fact I am also big fan of egrep multiple word searching capability. If you have enabled color coding for grep, egrep and fgrep in your .bashrc, or explicitly using them by providing --color option, you can use egrep to see existence of any word. For example, if you are working with FIX based Java application and have to analyse and debug FIX logs daily, you can use egrep to Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82276110572221488452012-12-11T17:02:49.867-08:002012-12-11T17:02:49.867-08:00If you look man page of egrep or fgrep than you fi...If you look man page of egrep or fgrep than you find that use of egrep and frep is deprecated and instead of using egrep you can use grep -E where E is for extended regular expression, similarly instead of grep you can use grep -F, where F stands for fixed string. One of my favorite grep command example is searching for multiple keywords using grep -E as some time they are related like parent andStevannoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-58735934356514621182012-11-15T12:48:19.437-08:002012-11-15T12:48:19.437-08:00How does one exclude multiple keywords?How does one exclude multiple keywords?OnlyJesusSaves.comhttps://www.blogger.com/profile/03712160496381143865noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-3105894836685358252012-08-26T22:54:55.504-07:002012-08-26T22:54:55.504-07:00grep -l command becomes savior for us as the line ...grep -l command becomes savior for us as the line which contains error doesn't contain /r/n and wc -l is printing 0 when invoked as<br /><b>grep "FAILED" Message.xml | wc -l </b> and we wanted to find total number of files which contains "FAILED" word, by running grep -l we were able to do that.<br /><br />grep -l "FAILED" *.xml | wc -l <br /><br />gives us Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-46965697844599283092012-08-14T01:50:02.742-07:002012-08-14T01:50:02.742-07:00Can you please suggest grep command examples for f...Can you please suggest grep command examples for following scenario:<br /><br />How to grep for String with spaces something like<br />grep ' ABC' file<br /><br />I think this will work because quotes will include the spaces as well while searching.<br /><br />How to grep for String with double quotes inside like<br /><br />grep '"ABC"' file<br /><br />this will also Adinoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26458974499157009812012-08-14T01:20:19.271-07:002012-08-14T01:20:19.271-07:00What is the grep command for following find comman...What is the grep command for following find command in Unix :<br /><br />find . -type d -perm -o=w<br /><br />which will find all files which are open and Have write permission on it.Adinoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-54747152958437813742012-07-09T03:40:20.394-07:002012-07-09T03:40:20.394-07:00Hi Javin, thanks for this, much appreciated! I wou...Hi Javin, thanks for this, much appreciated! I would like to share two more grep goodies I am frequently using:<br /><br />- grep -A x adds x lines to each matching line. Useful for finding information for which the match is only the headline.<br /><br />- In order to prevent grep from finding itself f.e. in ps -ef output or in the history, use square brackets around the first character. This Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2163515637227663352012-05-23T02:18:42.862-07:002012-05-23T02:18:42.862-07:00good post. context option of grep is very useful. ...good post. context option of grep is very useful. thanks buddyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-49028874363136129182012-05-10T03:08:46.059-07:002012-05-10T03:08:46.059-07:00Guys any one knows about how to use grep command t...Guys any one knows about how to use grep command to find a file in a directory. I am struggling to find files inside directories i.e. program needs to check one after other directory to find files. please helpmadhavnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-63972543300979872512012-05-10T03:06:02.868-07:002012-05-10T03:06:02.868-07:00I agree with Router, this site contains extremely ...I agree with Router, this site contains extremely useful example of grep command. no doubt that find and grep are two powerful search programs which is must know for any one working in Unix, Linux or Solaris but its always difficult to remember various options of grep or find and these examples helps to remember different options of unix grep command.Parthivnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-53462502188584868502012-01-29T20:58:20.646-08:002012-01-29T20:58:20.646-08:00True power of grep command in linux comes when you...True power of grep command in linux comes when you search a file deep in directory. its easy to find a file using grep command in unix in current of specified directory but if you don't know where is your file than find command is better option over grep.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43525682315718309262012-01-24T17:50:47.314-08:002012-01-24T17:50:47.314-08:00thanks a ton for this grep one liners in Linux. I ...thanks a ton for this grep one liners in Linux. I have been using your grep command in Linux operating system from few days and it helped me a lot. I also liked your find command in Unix and Linux tutorial those are just amazing information. please do share some more command examples which we can use while doing support.Joenoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-39256144871614944212012-01-06T10:01:23.835-08:002012-01-06T10:01:23.835-08:00The Best Linux Ubuntu Commands, Complete examples ...The Best Linux Ubuntu Commands, Complete examples best resource<br />http://thetechdata.blogspot.com/search/label/LinuxMuhammad Nasirhttps://www.blogger.com/profile/03968450137046245010noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-46615224742521630102011-12-16T04:15:21.019-08:002011-12-16T04:15:21.019-08:00Hi Ankur, I presume only way is to test your scrip...Hi Ankur, I presume only way is to test your script in those environment most of standard options like grep -c, grep -v are supported in all grep versions but to be sure I think only there man page or testing can do.Javin @ kill command examples in unixhttp://javarevisited.blogspot.com/2011/12/kill-command-unix-linux-example.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-65769098400561031772011-12-16T04:13:00.426-08:002011-12-16T04:13:00.426-08:00Hi Anonymous, it depends which version of grep is ...Hi Anonymous, it depends which version of grep is available in your linux machine, normally most of Linux machine has gnu version of grep installed on them.javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-60951217882691283512011-12-15T05:41:28.166-08:002011-12-15T05:41:28.166-08:00hi whats the standard version to use for grephi whats the standard version to use for grepAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-80047175706593439042011-12-15T05:40:35.859-08:002011-12-15T05:40:35.859-08:00any idea how to identify which options for grep ar...any idea how to identify which options for grep are standard to use in shell scripts as there are so many variations in grep like gnu grep , unix grep, bsd grep ... if we use one option in grep n if it does not support in unix grep ..so tell any idea how to identify which options to use..?Ankur Jhttps://www.blogger.com/profile/08932585379399754438noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-34290193879577731992011-12-06T18:02:35.649-08:002011-12-06T18:02:35.649-08:00pretty useful grep examples, Please include fgrep ...pretty useful grep examples, Please include fgrep examples and egrep examples as well.Joenoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-60585902868941481952011-12-05T00:03:50.835-08:002011-12-05T00:03:50.835-08:00which grep version have you tested this example ? ...which grep version have you tested this example ? gnu grep ?veeranoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-49704252698000387832011-12-01T22:46:25.799-08:002011-12-01T22:46:25.799-08:00Can you please put egrep examples in linux and fgr...Can you please put egrep examples in linux and fgrep examples in unix , I am confused between egrep and fgrep and want to chose between egrep and fgrep. please guide with samples.Anonymousnoreply@blogger.com