<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Grep</id>
	<title>Grep - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Grep"/>
	<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Grep&amp;action=history"/>
	<updated>2026-04-15T18:56:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.4</generator>
	<entry>
		<id>https://onnocenter.or.id/wiki/index.php?title=Grep&amp;diff=51236&amp;oldid=prev</id>
		<title>Onnowpurbo at 23:53, 31 May 2018</title>
		<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Grep&amp;diff=51236&amp;oldid=prev"/>
		<updated>2018-05-31T23:53:34Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:53, 31 May 2018&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l141&quot; &gt;Line 141:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 141:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  grep -ir “string1\|string2” dir_name&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  grep -ir “string1\|string2” dir_name&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;2 word di line yang sama&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; grep &amp;quot;word1&amp;quot; FILE | grep &amp;quot;word2&amp;quot;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
	<entry>
		<id>https://onnocenter.or.id/wiki/index.php?title=Grep&amp;diff=51235&amp;oldid=prev</id>
		<title>Onnowpurbo: Created page with &quot;How do I use grep command on Linux, Apple macOS/OS X, and Unix-like operating systems? Can you give me a simple examples of the grep command?  The grep command is used to sear...&quot;</title>
		<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Grep&amp;diff=51235&amp;oldid=prev"/>
		<updated>2018-05-31T23:47:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;How do I use grep command on Linux, Apple macOS/OS X, and Unix-like operating systems? Can you give me a simple examples of the grep command?  The grep command is used to sear...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;How do I use grep command on Linux, Apple macOS/OS X, and Unix-like operating systems? Can you give me a simple examples of the grep command?&lt;br /&gt;
&lt;br /&gt;
The grep command is used to search text. It searches the given file for lines containing a match to the given strings or words. It is one of the most useful commands on Linux and Unix-like system. Let us see how to use grep on a Linux or Unix like system.&lt;br /&gt;
&lt;br /&gt;
Did you know?&lt;br /&gt;
&lt;br /&gt;
The name, “grep”, derives from the command used to perform a similar operation, using the Unix/Linux text editor ed:&lt;br /&gt;
g/re/p&lt;br /&gt;
The grep command syntax&lt;br /&gt;
&lt;br /&gt;
The syntax is as follows:&lt;br /&gt;
&lt;br /&gt;
 grep 'word' filename&lt;br /&gt;
 grep 'word' file1 file2 file3&lt;br /&gt;
 grep 'string1 string2'  filename&lt;br /&gt;
 cat otherfile | grep 'something'&lt;br /&gt;
 command | grep 'something'&lt;br /&gt;
 command option1 | grep 'data'&lt;br /&gt;
 grep --color 'data' fileName&lt;br /&gt;
&lt;br /&gt;
How do I use grep to search a file?&lt;br /&gt;
&lt;br /&gt;
Search /etc/passwd file for boo user, enter:&lt;br /&gt;
&lt;br /&gt;
 $ grep boo /etc/passwd&lt;br /&gt;
&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
 foo:x:1000:1000:foo,,,:/home/foo:/bin/ksh&lt;br /&gt;
&lt;br /&gt;
You can force grep to ignore word case i.e match boo, Boo, BOO and all other combination with the -i option:&lt;br /&gt;
&lt;br /&gt;
 $ grep -i &amp;quot;boo&amp;quot; /etc/passwd&lt;br /&gt;
&lt;br /&gt;
How to use grep recursively&lt;br /&gt;
&lt;br /&gt;
You can search recursively i.e. read all files under each directory for a string “192.168.1.5”&lt;br /&gt;
&lt;br /&gt;
 $ grep -r &amp;quot;192.168.1.5&amp;quot; /etc/&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
 $ grep -R &amp;quot;192.168.1.5&amp;quot; /etc/&lt;br /&gt;
&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
 /etc/ppp/options:# ms-wins 192.168.1.50&lt;br /&gt;
 /etc/ppp/options:# ms-wins 192.168.1.51&lt;br /&gt;
 /etc/NetworkManager/system-connections/Wired connection 1:addresses1=192.168.1.5;24;192.168.1.2;&lt;br /&gt;
&lt;br /&gt;
You will see result for 192.168.1.5 on a separate line preceded by the name of the file (such as /etc/ppp/options) in which it was found. The inclusion of the file names in the output data can be suppressed by using the -h option as follows:&lt;br /&gt;
&lt;br /&gt;
 $ grep -h -R &amp;quot;192.168.1.5&amp;quot; /etc/&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
 $ grep -hR &amp;quot;192.168.1.5&amp;quot; /etc/&lt;br /&gt;
&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
 # ms-wins 192.168.1.50&lt;br /&gt;
 # ms-wins 192.168.1.51&lt;br /&gt;
 addresses1=192.168.1.5;24;192.168.1.2;&lt;br /&gt;
&lt;br /&gt;
How to use grep to search words only&lt;br /&gt;
&lt;br /&gt;
When you search for boo, grep will match fooboo, boo123, barfoo35 and more. You can force the grep command to select only those lines containing matches that form whole words i.e. match only boo word:&lt;br /&gt;
&lt;br /&gt;
 $ grep -w &amp;quot;boo&amp;quot; file&lt;br /&gt;
&lt;br /&gt;
How to use grep to search 2 different words&lt;br /&gt;
&lt;br /&gt;
Use the egrep command as follows:&lt;br /&gt;
&lt;br /&gt;
 $ egrep -w 'word1|word2' /path/to/file&lt;br /&gt;
 grep -E &amp;quot;word1|word2&amp;quot; /path/dir&lt;br /&gt;
&lt;br /&gt;
How can I count line when words has been matched&lt;br /&gt;
&lt;br /&gt;
The grep can report the number of times that the pattern has been matched for each file using -c (count) option:&lt;br /&gt;
&lt;br /&gt;
 $ grep -c 'word' /path/to/file&lt;br /&gt;
&lt;br /&gt;
Pass the -n option to precede each line of output with the number of the line in the text file from which it was obtained:&lt;br /&gt;
&lt;br /&gt;
 $ grep -n 'root' /etc/passwd&lt;br /&gt;
&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
 1:root:x:0:0:root:/root:/bin/bash&lt;br /&gt;
 1042:rootdoor:x:0:0:rootdoor:/home/rootdoor:/bin/csh&lt;br /&gt;
 3319:initrootapp:x:0:0:initrootapp:/home/initroot:/bin/ksh&lt;br /&gt;
&lt;br /&gt;
Force grep invert match&lt;br /&gt;
&lt;br /&gt;
You can use -v option to print inverts the match; that is, it matches only those lines that do not contain the given word. For example print all line that do not contain the word bar:&lt;br /&gt;
&lt;br /&gt;
 $ grep -v bar /path/to/file&lt;br /&gt;
&lt;br /&gt;
UNIX / Linux pipes and grep command&lt;br /&gt;
&lt;br /&gt;
grep command often used with shell pipes. In this example, show the name of the hard disk devices:&lt;br /&gt;
&lt;br /&gt;
 # dmesg | egrep '(s|h)d[a-z]'&lt;br /&gt;
&lt;br /&gt;
Display cpu model name:&lt;br /&gt;
&lt;br /&gt;
 # cat /proc/cpuinfo | grep -i 'Model'&lt;br /&gt;
&lt;br /&gt;
However, above command can be also used as follows without shell pipe:&lt;br /&gt;
&lt;br /&gt;
 # grep -i 'Model' /proc/cpuinfo&lt;br /&gt;
&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
 model		: 30&lt;br /&gt;
 model name	: Intel(R) Core(TM) i7 CPU       Q 820  @ 1.73GHz&lt;br /&gt;
 model		: 30&lt;br /&gt;
 model name	: Intel(R) Core(TM) i7 CPU       Q 820  @ 1.73GHz&lt;br /&gt;
&lt;br /&gt;
How do I list just the names of matching files?&lt;br /&gt;
&lt;br /&gt;
Use the -l option to list file name whose contents mention main():&lt;br /&gt;
&lt;br /&gt;
 $ grep -l 'main' *.c&lt;br /&gt;
&lt;br /&gt;
Finally, you can force grep to display output in colors, enter:&lt;br /&gt;
&lt;br /&gt;
 $ grep --color vivek /etc/passwd&lt;br /&gt;
&lt;br /&gt;
Sample outputs:&lt;br /&gt;
Grep command in action on Linux and Unix like system&lt;br /&gt;
Grep command in action&lt;br /&gt;
&lt;br /&gt;
If you enjoyed the grep tutorial, then you might like to read our “Regular Expressions in Grep” tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Search Multiple String==&lt;br /&gt;
&lt;br /&gt;
 grep -ir “string1\|string2” dir_name&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>