<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: HowTo: Use grep Command In Linux / UNIX [ Examples ]</title> <atom:link href="http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/feed/" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/</link> <description>Every answer asks a more beautiful question.</description> <lastBuildDate>Fri, 10 Feb 2012 19:55:56 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: jay</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67743</link> <dc:creator>jay</dc:creator> <pubDate>Mon, 06 Feb 2012 03:38:33 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67743</guid> <description>how to find/search particular date &amp; time when we have more than 1000(times and date) stored in a log file?</description> <content:encoded><![CDATA[<p>how to find/search particular date &amp; time when we have more than 1000(times and date) stored in a log file?</p> ]]></content:encoded> </item> <item><title>By: joanna</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67405</link> <dc:creator>joanna</dc:creator> <pubDate>Mon, 23 Jan 2012 07:00:57 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67405</guid> <description>what if we want the output of one command, minus the output of another command... ? by using grep -v?
for example ls and ls file.txt (i.e print the output of ls, except the ones related to file, using grep... )</description> <content:encoded><![CDATA[<p>what if we want the output of one command, minus the output of another command&#8230; ? by using grep -v?<br
/> for example ls and ls file.txt (i.e print the output of ls, except the ones related to file, using grep&#8230; )</p> ]]></content:encoded> </item> <item><title>By: simmy</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67384</link> <dc:creator>simmy</dc:creator> <pubDate>Sun, 22 Jan 2012 15:59:52 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67384</guid> <description>really super site to learn linux grep command</description> <content:encoded><![CDATA[<p>really super site to learn linux grep command</p> ]]></content:encoded> </item> <item><title>By: perg</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67241</link> <dc:creator>perg</dc:creator> <pubDate>Fri, 20 Jan 2012 05:51:56 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-67241</guid> <description>Thanks, was helpful even 4 years later!</description> <content:encoded><![CDATA[<p>Thanks, was helpful even 4 years later!</p> ]]></content:encoded> </item> <item><title>By: Akiva</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-66400</link> <dc:creator>Akiva</dc:creator> <pubDate>Thu, 05 Jan 2012 07:51:17 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-66400</guid> <description>thanks</description> <content:encoded><![CDATA[<p>thanks</p> ]]></content:encoded> </item> <item><title>By: vivek</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-66279</link> <dc:creator>vivek</dc:creator> <pubDate>Mon, 02 Jan 2012 14:49:15 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-66279</guid> <description>i need to grep only one occurrence of character / in std output  another unix coomand on LINUX platform as example below :-
jar -tf *.zip &#124;  grep &#039;\/&#039;
installer/
installer/lib/
installer/lib/
.........
anyone please help me with solution</description> <content:encoded><![CDATA[<p>i need to grep only one occurrence of character / in std output  another unix coomand on LINUX platform as example below :-</p><p>jar -tf *.zip |  grep &#8216;\/&#8217;<br
/> installer/<br
/> installer/lib/<br
/> installer/lib/<br
/> &#8230;&#8230;&#8230;</p><p>anyone please help me with solution</p> ]]></content:encoded> </item> <item><title>By: mj</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-66199</link> <dc:creator>mj</dc:creator> <pubDate>Fri, 30 Dec 2011 06:13:58 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-66199</guid> <description>i need find the starting &quot;p&quot; in all the files at a single directory.</description> <content:encoded><![CDATA[<p>i need find the starting &#8220;p&#8221; in all the files at a single directory.</p> ]]></content:encoded> </item> <item><title>By: Shehzad-Bilal</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65853</link> <dc:creator>Shehzad-Bilal</dc:creator> <pubDate>Wed, 21 Dec 2011 07:22:01 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65853</guid> <description>Great tutorial</description> <content:encoded><![CDATA[<p>Great tutorial</p> ]]></content:encoded> </item> <item><title>By: ayat sbih</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65513</link> <dc:creator>ayat sbih</dc:creator> <pubDate>Sun, 11 Dec 2011 20:54:44 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65513</guid> <description>can you help me to learn how i can replace one word with another?</description> <content:encoded><![CDATA[<p>can you help me to learn how i can replace one word with another?</p> ]]></content:encoded> </item> <item><title>By: Manish</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65252</link> <dc:creator>Manish</dc:creator> <pubDate>Wed, 07 Dec 2011 05:34:31 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65252</guid> <description>so  much  helpful  nd  clear  document.............................................
thanks</description> <content:encoded><![CDATA[<p>so  much  helpful  nd  clear  document&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;</p><p>thanks</p> ]]></content:encoded> </item> <item><title>By: jetole</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65082</link> <dc:creator>jetole</dc:creator> <pubDate>Fri, 02 Dec 2011 13:53:58 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65082</guid> <description>Oh P.S.
I don&#039;t know what the name of the oracle server is. In my first example I used:
&lt;pre&gt;
ps -C oracle
&lt;/pre&gt;
This was assuming the name of the command running is oracle however if you know part of the command name then you can find the exact command name by running:
&lt;pre&gt;
ps -A -o ucmd --no-headers &#124; grep -i oracle
&lt;/pre&gt;
The output ucmd shows only the command running without any arguments unlike &quot;-o cmd&quot; which shows the command and all arguments so when you use &quot;-o ucmd&quot; and do a case insensitive search for oracle, it will return any commands that are either named oracle or have oracle as part of their name but it will not return the grep command because ucmd isn&#039;t showing arguments so the ps listing, for the line which matches grep will just show &quot;grep&quot; and not &quot;grep -i oracle&quot;. When you run the above command to find your commands name, you can replace oracle with all or part of the command you are looking for and it will return any patches, case insensitive (-i option for case insensitive).</description> <content:encoded><![CDATA[<p>Oh P.S.</p><p>I don&#8217;t know what the name of the oracle server is. In my first example I used:</p><pre>
ps -C oracle
</pre><p>This was assuming the name of the command running is oracle however if you know part of the command name then you can find the exact command name by running:</p><pre>
ps -A -o ucmd --no-headers | grep -i oracle
</pre><p>The output ucmd shows only the command running without any arguments unlike &#8220;-o cmd&#8221; which shows the command and all arguments so when you use &#8220;-o ucmd&#8221; and do a case insensitive search for oracle, it will return any commands that are either named oracle or have oracle as part of their name but it will not return the grep command because ucmd isn&#8217;t showing arguments so the ps listing, for the line which matches grep will just show &#8220;grep&#8221; and not &#8220;grep -i oracle&#8221;. When you run the above command to find your commands name, you can replace oracle with all or part of the command you are looking for and it will return any patches, case insensitive (-i option for case insensitive).</p> ]]></content:encoded> </item> <item><title>By: jetole</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65081</link> <dc:creator>jetole</dc:creator> <pubDate>Fri, 02 Dec 2011 13:47:49 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-65081</guid> <description>while some of this may work, it&#039;s a rather inefficient way to do it. You can read the man page for both ps and grep by running the commands &quot;man ps&quot; and &quot;man grep&quot; (without the quotes) to get a good idea of what all the options are. In doing so you can see that you can specify the command you are looking for in ps using the -C option, you can format the output to look how you want with the -o option and you can remove the headers which usually become negligible when using the -o option by adding the --no-headers option. Additionally with grep their is a -q option which causes grep to be quiet so there would be no need to redirect output to /dev/null and another useful option would be -w which matches word only. Additionally, if you run the command &quot;help if&quot; (without the quotes) or &quot;man bash&quot; and skip to the if section, you will see that the if clause evaluates the return of a command. &quot;[&quot; in a if clause is a command (either a shell built-in usually or can be an external command. You likely have both but the shell built-in takes precedence. Because of this, you can use grep as the command if looks at instead of the [ command/clause and narrow down your code a lot more to look something like this:
&lt;pre&gt;
orasid=&quot;tiger&quot;
if ps -C oracle --no-headers -o cmd &#124; grep -qw &quot;${orasid}&quot;
then
echo &quot;${orasid} found. PID&#039;s of oracle containing ${orasid} listed below&quot;
ps -C oracle -o pid,cmd &#124; grep -qw &quot;${orasid}&quot;
else
echo &quot;No instance of oracle found with ${orasid} in the options&quot;
fi
&lt;/pre&gt;
I&#039;m using ${variable} here instead of $variable which isn&#039;t supported under all shells but it is supported under bash. It&#039;s not necessarily needed here however I prefer to use most of the time (there are some instances where you shouldn&#039;t use it) because I consider it a safe way to protect against errors where perhaps part of the text is not part of the variable, for example, if my variable named num containing the number 5 and I want to echo &quot;The 5th number&quot; where I use the variable num for 5 then, if I wrote
&lt;pre&gt;
num=5
echo &quot;The $numth number&quot;
# This would print &quot;The number&quot;. It would not know that th isn&#039;t part of the variable and it would
# think the variable is all of $numth which doesn&#039;t exist so it wouldn&#039;t print anything for that var
&lt;/pre&gt;
instead
&lt;pre&gt;
num=5
echo &quot;The ${num}th number&quot;
# This would print &quot;The 5th number&quot;. Using ${} we define exactly where the variable starts and
# ends so it knows that num is the variable and the &quot;th&quot; is just text to echo.
&lt;/pre&gt;
Again, the ${} isn&#039;t portable and may not work outside of bash but, on the other hand, bash has been around longer then Linux (bash since 89, Linux since 91) and is the default shell on most Linux distros so it&#039;s there to use and really worth it.
Another plus about using bash, again, this isn&#039;t portable and may not work outside of bash but you can use if [[ my_test ]] instead of if [ my_test]. [[ should only be a shell built in. What I mean by this is that [ can either be a shell built in function (and most commonly it&#039;s the shell built in you use or [ can also be a command. [[ is almost never the name of a command and hence why it&#039;s not portable but if you are using bash and you probably should be unless you know why you want to use another shell more but if you are using bash then [[ and ]] is less error prone then [ and ] and allows you to perform multiple checks within the same test clause, for example if you wanted to test to make sure one check is correct or another check is correct using [ and ], the safest way to do so would be to have to separate if statements outside of each other both performing the same action i.e.
&lt;pre&gt;
if [ 1 == 1 ]
then
perform this action
fi
if [ 2 == 2 ]
then
perform that exact same action
fi
&lt;/pre&gt;
In theory you can use:
&lt;pre&gt;
if [ 1 == 1 ] &#124;&#124; [ 2 == 2 ]
&lt;/pre&gt;
However chaining or statements like that in multiple commands to the if statement to see if either one is true is frowned upon and is said that it may cause unexpected results. The proper way to do this from bash would be:
&lt;pre&gt;
if [[ 1 == 1 &#124;&#124; 2 == 2 ]]
then
perform this action
fi
&lt;/pre&gt;
If you try to use:
&lt;pre&gt;
if [ 1 == 1 &#124;&#124; 2 == 2 ]
then
perform this action
fi
&lt;/pre&gt;
then it will fail because it will treat the &#124;&#124; inside the [ and ] as a bash &#124;&#124; statement between two command thinking &quot;2 == 2 ]&quot; is a second command and will complain that you are missing the closing ] on the first command. Using [[ and ]] you can also use an AND clause to all tests are true instead of if any one test is true, for example
&lt;pre&gt;
if [[ 1 == 2 &#124;&#124; 2 == 2 ]]
# This returns true and performs the action in the if clause because it only needs one of the two to be true.
if [[ 1 == 2 &amp;&amp; 2 == 2 ]]
# This returns false and performs the action in the else clause of nothing if their is no else clause and this would require both statements to be true which they are not because 1 does not equal 2.
&lt;/pre&gt;
For more details on all the operators you can use within [ ] and [[ ]], run the commands &quot;help test&quot;, &quot;help [&quot; or &quot;man bash&quot; (without the quotes) and if you look at the man page for bash, jump down to the section &quot;CONDITIONAL EXPRESSIONS&quot; (again, without the quotes).
Another handy test method to use inside bash is (( and )) for number only comparison. You can use [[ and ]] to test if a file exists or if a string is the string you want etc but (( and )) are only for numbers (more specifically integers but I&#039;ll dive into that in a moment). which can help make sure you are not accidentally testing something you shouldn&#039;t be. Also you can use &quot;declare -i&quot; (sans the quotes) to define a variable that can only hold an integer and if anything is assigned to it that is not an integer then it will default to 0.
&lt;pre&gt;
declare -i my_variable=&quot;boat&quot;
echo &quot;${my_variable}&quot;
# This will print 0 because my_variable doesn&#039;t allow strings when defined with declare -i
declare -i my_variable=15
echo &quot;${my_variable}&quot;
# This will print 15 because it will only accept integers.
declare -i my_variable=15
if ((${my_variable} &gt; 10))
then
echo &quot;${my_variable} is greater then 10&quot;
else
echo &quot;${my_variable} is 10 or less then 10&quot;
fi
# This will print &quot;15 is greater then 10&quot;. If you change the var to 10 or lower then it will execute the else statement.
declare -i myvar=1.5
# This will cause an error because integer variable only allow whole numbers.
if (( 1.5 == 1.5 ))
# This will also cause an error because (( and )) will work with integers / whole numbers.
&lt;/pre&gt;
You can store decimal numbers in regular variables though there is no special var designed only for decimals. There are a lot of different ways to test decimal numbers but the best, IMHO, is using the command bc command. You can use this inside a (( )) test by calling the bc command using command substitution with $(command). People often use back ticks, &quot; `command` &quot; (sans the double quotes), for command substitution which, again, back ticks are portable and $( ) doesn&#039;t work in all shells however, if you are using bash and you probably should be using bash then $(command) is more more powerful and back ticks are much more prone to error. When using bc to perform a comparison, for example, if x &lt; y, then bc prints 1 when it is true (if x really is &lt; y) else it prints 0 if the comparison is false (compare x &lt; y but if x is greater then or equal to y then x &lt; y is false so it prints a one). Here&#039;s an example of how to compare decimal numbers.
&lt;pre&gt;
myvar=12.5
if (( $(bc &lt;&lt;&lt; &quot;${myvar} &lt; 15.2&quot;) == 1)
then
echo &quot;${myvar} is less then 15.2&quot;
else
echo &quot;${myvar is greater then or equal to 15.2&quot;
fi
# The if statement is checking to see if the number printed by the $(command) is equal to 1.
# bc is saying is 12.5 less then 15.2 which it is so the comparison is true so bc prints 1
# Knowing that bc is printing one, then the if statement could be simplified for demonstation purposes by saying
if (( 1 == 1 ))
# That doesn&#039;t make sense to test just because it&#039;s too simple but that gives you an example of how the if statement looks to bash based on the result provided by bc in the command substitution.
# If you just want to do basic math on decimal numbers in bash you can do something like
num1=12.5
num2=15.2
sum=$(bc &lt;&lt;&lt; &quot;${num1} + ${num2}&quot;
echo &quot;The sum of ${num1} + ${num2} = ${sum}&quot;
# This will print: The sum of 12.5 + 15.2 = 27.7
&lt;/pre&gt;
I think I have gone pretty sufficiently above, beyond and way off topic here so I am going to quit before I bore anyone to death but I really did want to enlighten people to the power of bash and it&#039;s capabilities and I believe I have done a good job at starting that so far so I&#039;m gonna quit while I&#039;m ahead, if I am ;-)</description> <content:encoded><![CDATA[<p>while some of this may work, it&#8217;s a rather inefficient way to do it. You can read the man page for both ps and grep by running the commands &#8220;man ps&#8221; and &#8220;man grep&#8221; (without the quotes) to get a good idea of what all the options are. In doing so you can see that you can specify the command you are looking for in ps using the -C option, you can format the output to look how you want with the -o option and you can remove the headers which usually become negligible when using the -o option by adding the &#8211;no-headers option. Additionally with grep their is a -q option which causes grep to be quiet so there would be no need to redirect output to /dev/null and another useful option would be -w which matches word only. Additionally, if you run the command &#8220;help if&#8221; (without the quotes) or &#8220;man bash&#8221; and skip to the if section, you will see that the if clause evaluates the return of a command. &#8220;[" in a if clause is a command (either a shell built-in usually or can be an external command. You likely have both but the shell built-in takes precedence. Because of this, you can use grep as the command if looks at instead of the [ command/clause and narrow down your code a lot more to look something like this:</p><pre>
orasid="tiger"
if ps -C oracle --no-headers -o cmd | grep -qw "${orasid}"
then
        echo "${orasid} found. PID's of oracle containing ${orasid} listed below"
        ps -C oracle -o pid,cmd | grep -qw "${orasid}"
else
        echo "No instance of oracle found with ${orasid} in the options"
fi
</pre><p>I'm using ${variable} here instead of $variable which isn't supported under all shells but it is supported under bash. It's not necessarily needed here however I prefer to use most of the time (there are some instances where you shouldn't use it) because I consider it a safe way to protect against errors where perhaps part of the text is not part of the variable, for example, if my variable named num containing the number 5 and I want to echo "The 5th number" where I use the variable num for 5 then, if I wrote</p><pre>
num=5
echo "The $numth number"
# This would print "The number". It would not know that th isn't part of the variable and it would
# think the variable is all of $numth which doesn't exist so it wouldn't print anything for that var
</pre><p>instead</p><pre>
num=5
echo "The ${num}th number"
# This would print "The 5th number". Using ${} we define exactly where the variable starts and
# ends so it knows that num is the variable and the "th" is just text to echo.
</pre><p>Again, the ${} isn't portable and may not work outside of bash but, on the other hand, bash has been around longer then Linux (bash since 89, Linux since 91) and is the default shell on most Linux distros so it's there to use and really worth it.</p><p>Another plus about using bash, again, this isn't portable and may not work outside of bash but you can use if [[ my_test ]] instead of if [ my_test]. [[ should only be a shell built in. What I mean by this is that [ can either be a shell built in function (and most commonly it's the shell built in you use or [ can also be a command. [[ is almost never the name of a command and hence why it's not portable but if you are using bash and you probably should be unless you know why you want to use another shell more but if you are using bash then [[ and ]] is less error prone then [ and ] and allows you to perform multiple checks within the same test clause, for example if you wanted to test to make sure one check is correct or another check is correct using [ and ], the safest way to do so would be to have to separate if statements outside of each other both performing the same action i.e.</p><pre>
if [ 1 == 1 ]
then
        perform this action
fi
if [ 2 == 2 ]
then
        perform that exact same action
fi
</pre><p>In theory you can use:</p><pre>
if [ 1 == 1 ] || [ 2 == 2 ]
</pre><p>However chaining or statements like that in multiple commands to the if statement to see if either one is true is frowned upon and is said that it may cause unexpected results. The proper way to do this from bash would be:</p><pre>
if [[ 1 == 1 || 2 == 2 ]]
then
        perform this action
fi
</pre><p>If you try to use:</p><pre>
if [ 1 == 1 || 2 == 2 ]
then
        perform this action
fi
</pre><p>then it will fail because it will treat the || inside the [ and ] as a bash || statement between two command thinking &#8220;2 == 2 ]&#8221; is a second command and will complain that you are missing the closing ] on the first command. Using [[ and ]] you can also use an AND clause to all tests are true instead of if any one test is true, for example</p><pre>
if [[ 1 == 2 || 2 == 2 ]]
# This returns true and performs the action in the if clause because it only needs one of the two to be true.
if [[ 1 == 2 &amp;&amp; 2 == 2 ]]
# This returns false and performs the action in the else clause of nothing if their is no else clause and this would require both statements to be true which they are not because 1 does not equal 2.
</pre><p>For more details on all the operators you can use within [ ] and [[ ]], run the commands &#8220;help test&#8221;, &#8220;help [" or "man bash" (without the quotes) and if you look at the man page for bash, jump down to the section "CONDITIONAL EXPRESSIONS" (again, without the quotes).</p><p>Another handy test method to use inside bash is (( and )) for number only comparison. You can use [[ and ]] to test if a file exists or if a string is the string you want etc but (( and )) are only for numbers (more specifically integers but I&#8217;ll dive into that in a moment). which can help make sure you are not accidentally testing something you shouldn&#8217;t be. Also you can use &#8220;declare -i&#8221; (sans the quotes) to define a variable that can only hold an integer and if anything is assigned to it that is not an integer then it will default to 0.</p><pre>
declare -i my_variable="boat"
echo "${my_variable}"
# This will print 0 because my_variable doesn't allow strings when defined with declare -i
declare -i my_variable=15
echo "${my_variable}"
# This will print 15 because it will only accept integers.
declare -i my_variable=15
if ((${my_variable} &gt; 10))
then
        echo "${my_variable} is greater then 10"
else
        echo "${my_variable} is 10 or less then 10"
fi
# This will print "15 is greater then 10". If you change the var to 10 or lower then it will execute the else statement.
declare -i myvar=1.5
# This will cause an error because integer variable only allow whole numbers.
if (( 1.5 == 1.5 ))
# This will also cause an error because (( and )) will work with integers / whole numbers.
</pre><p>You can store decimal numbers in regular variables though there is no special var designed only for decimals. There are a lot of different ways to test decimal numbers but the best, IMHO, is using the command bc command. You can use this inside a (( )) test by calling the bc command using command substitution with $(command). People often use back ticks, &#8221; `command` &#8221; (sans the double quotes), for command substitution which, again, back ticks are portable and $( ) doesn&#8217;t work in all shells however, if you are using bash and you probably should be using bash then $(command) is more more powerful and back ticks are much more prone to error. When using bc to perform a comparison, for example, if x &lt; y, then bc prints 1 when it is true (if x really is &lt; y) else it prints 0 if the comparison is false (compare x &lt; y but if x is greater then or equal to y then x &lt; y is false so it prints a one). Here&#039;s an example of how to compare decimal numbers.</p><pre>
myvar=12.5
if (( $(bc &lt;&lt;&lt; &quot;${myvar} &lt; 15.2&quot;) == 1)
then
        echo &quot;${myvar} is less then 15.2&quot;
else
        echo &quot;${myvar is greater then or equal to 15.2&quot;
fi
# The if statement is checking to see if the number printed by the $(command) is equal to 1.
# bc is saying is 12.5 less then 15.2 which it is so the comparison is true so bc prints 1
# Knowing that bc is printing one, then the if statement could be simplified for demonstation purposes by saying
if (( 1 == 1 ))
# That doesn&#039;t make sense to test just because it&#039;s too simple but that gives you an example of how the if statement looks to bash based on the result provided by bc in the command substitution.
# If you just want to do basic math on decimal numbers in bash you can do something like
num1=12.5
num2=15.2
sum=$(bc &lt;&lt;&lt; &quot;${num1} + ${num2}&quot;
echo &quot;The sum of ${num1} + ${num2} = ${sum}&quot;
# This will print: The sum of 12.5 + 15.2 = 27.7
</pre><p>I think I have gone pretty sufficiently above, beyond and way off topic here so I am going to quit before I bore anyone to death but I really did want to enlighten people to the power of bash and it&#8217;s capabilities and I believe I have done a good job at starting that so far so I&#8217;m gonna quit while I&#8217;m ahead, if I am ;-)</p> ]]></content:encoded> </item> <item><title>By: siva</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-64742</link> <dc:creator>siva</dc:creator> <pubDate>Wed, 23 Nov 2011 08:04:10 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-64742</guid> <description>Hi ,
I&#039;m new to linux , I would like to know  how to identify the  blank files in linux  for example
[root@xxxxxx]# cat dfpAL52sS5028817
[root@xxxxxx]#
[root@xxxxxx]#
[root@xxxxxx]#
I would like to identify the files that shows blank as above , can  any one  help me this.
advance thanks,
Siva.</description> <content:encoded><![CDATA[<p>Hi ,</p><p>I&#8217;m new to linux , I would like to know  how to identify the  blank files in linux  for example<br
/> [root@xxxxxx]# cat dfpAL52sS5028817</p><p>[root@xxxxxx]#<br
/> [root@xxxxxx]#<br
/> [root@xxxxxx]#</p><p>I would like to identify the files that shows blank as above , can  any one  help me this.</p><p>advance thanks,<br
/> Siva.</p> ]]></content:encoded> </item> <item><title>By: zip</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-64688</link> <dc:creator>zip</dc:creator> <pubDate>Mon, 21 Nov 2011 15:23:55 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-64688</guid> <description>how do i do this- grep -w &quot;...&quot; filename
with the comand &quot;sed&quot;?</description> <content:encoded><![CDATA[<p>how do i do this- grep -w &#8220;&#8230;&#8221; filename<br
/> with the comand &#8220;sed&#8221;?</p> ]]></content:encoded> </item> <item><title>By: Mohanraj</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-63853</link> <dc:creator>Mohanraj</dc:creator> <pubDate>Mon, 24 Oct 2011 15:04:31 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-63853</guid> <description>Hi,
you can try out the below command..
grep -i ^t..spq filename
Best regards,
Mohanraj</description> <content:encoded><![CDATA[<p>Hi,</p><p>you can try out the below command..</p><p>grep -i ^t..spq filename</p><p>Best regards,<br
/> Mohanraj</p> ]]></content:encoded> </item> <item><title>By: chandu</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-63690</link> <dc:creator>chandu</dc:creator> <pubDate>Wed, 19 Oct 2011 12:03:47 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-63690</guid> <description>very usefull.........</description> <content:encoded><![CDATA[<p>very usefull&#8230;&#8230;&#8230;</p> ]]></content:encoded> </item> <item><title>By: ghafil</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-63644</link> <dc:creator>ghafil</dc:creator> <pubDate>Tue, 18 Oct 2011 10:18:03 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-63644</guid> <description>how to do grep -v &#039;pattern1&#124;pattern2&#124;pattern3&#039; with invert search?</description> <content:encoded><![CDATA[<p>how to do grep -v &#8216;pattern1|pattern2|pattern3&#8242; with invert search?</p> ]]></content:encoded> </item> <item><title>By: Aim&#38;fire</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-62930</link> <dc:creator>Aim&#38;fire</dc:creator> <pubDate>Thu, 29 Sep 2011 03:42:43 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-62930</guid> <description>How can I use grep with wc and uniq commands?  I know I have to use piping, but I can&#039;t seem to get the order right.  Can someone help?</description> <content:encoded><![CDATA[<p>How can I use grep with wc and uniq commands?  I know I have to use piping, but I can&#8217;t seem to get the order right.  Can someone help?</p> ]]></content:encoded> </item> <item><title>By: sapna</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-62685</link> <dc:creator>sapna</dc:creator> <pubDate>Thu, 22 Sep 2011 15:09:05 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-62685</guid> <description>Q1)by using grep command how do display all those lines in a file that has only uppercase characters?
Q2)by using grep select all those lines which has a ?(mark) at the end of line?
Q3) by using grep command how select all those lines which has any of the following patterns ab,aab,aaab or like others?</description> <content:encoded><![CDATA[<p>Q1)by using grep command how do display all those lines in a file that has only uppercase characters?<br
/> Q2)by using grep select all those lines which has a ?(mark) at the end of line?<br
/> Q3) by using grep command how select all those lines which has any of the following patterns ab,aab,aaab or like others?</p> ]]></content:encoded> </item> <item><title>By: sudheer</title><link>http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-62335</link> <dc:creator>sudheer</dc:creator> <pubDate>Sun, 11 Sep 2011 02:55:12 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#comment-62335</guid> <description>1)	Use grep (or awk) to output all lines in a given file which contain employee ID numbers. Assume that each employee ID number consists of 1-4 digits followed by two letters: the first is either a W or a S and the second is either a C or a T. ID numbers never start with 0s. Further assume that an employee ID is always proceeded by some type of white space – tab, blank, new line etc. However, there might be characters after it, for example punctuation.
What to turn in: Turn in three things:
a.	A file with the regular expression which can directly be used by grep (or awk)
b.	A text file which you used to test your regular expression. Make sure that you include valid and ‘invalid’ employee IDs, have them at the beginning and the end of lines, sentences, etc.
c.	A second document which re-writes the regular expression in a more human-readable form and explains the purpose of the different components of the regular expression. Also include a short explanation of your test cases.
2)	Use grep (or awk) to output all the lines in a given file which contain a decimal number (e.g. a number which includes a decimal point). Decimal numbers do not have leading zeros but they might have trailing zeros. Assume the number is always surrounded by white space.
What to turn in: The same three things as above (except, of course, for this problem).
3)	Write a regular expression for the valid identifiers in Java. You are allowed to use ‘shortcuts’, but need to make sure that you specify exactly what they are (e.g. if you use digit specify that that means 0, 1, 2, 3, ….9.)</description> <content:encoded><![CDATA[<p>1)	Use grep (or awk) to output all lines in a given file which contain employee ID numbers. Assume that each employee ID number consists of 1-4 digits followed by two letters: the first is either a W or a S and the second is either a C or a T. ID numbers never start with 0s. Further assume that an employee ID is always proceeded by some type of white space – tab, blank, new line etc. However, there might be characters after it, for example punctuation.<br
/> What to turn in: Turn in three things:</p><p>a.	A file with the regular expression which can directly be used by grep (or awk)</p><p>b.	A text file which you used to test your regular expression. Make sure that you include valid and ‘invalid’ employee IDs, have them at the beginning and the end of lines, sentences, etc.</p><p>c.	A second document which re-writes the regular expression in a more human-readable form and explains the purpose of the different components of the regular expression. Also include a short explanation of your test cases.</p><p>2)	Use grep (or awk) to output all the lines in a given file which contain a decimal number (e.g. a number which includes a decimal point). Decimal numbers do not have leading zeros but they might have trailing zeros. Assume the number is always surrounded by white space.</p><p>What to turn in: The same three things as above (except, of course, for this problem).</p><p>3)	Write a regular expression for the valid identifiers in Java. You are allowed to use ‘shortcuts’, but need to make sure that you specify exactly what they are (e.g. if you use digit specify that that means 0, 1, 2, 3, ….9.)</p> ]]></content:encoded> </item> </channel> </rss>
