<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Search and Display only searched string in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975042#M758761</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;1)&lt;BR /&gt;if fgrep -q "string" file1 file2 ...&lt;BR /&gt;then print "string"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;2) More than one possibility:&lt;BR /&gt;- You can export the variables in scripta and use them in scriptb ...:&lt;BR /&gt;scripta:&lt;BR /&gt;export var1=value1&lt;BR /&gt;export var2=value2&lt;BR /&gt;...&lt;BR /&gt;scriptb&lt;BR /&gt;&lt;BR /&gt;... and in scriptb just use that varible, but check the varibles first:&lt;BR /&gt;[ -n "$var1" ] || print -u2 var1 empty&lt;BR /&gt;...&lt;BR /&gt;- a 'short hand' export depends on the way you set your variables; this is possible as well in scripta:&lt;BR /&gt;var1=value1 var2=value2 scriptb&lt;BR /&gt;&lt;BR /&gt;- you can provide the variables as parameters to scriptb:&lt;BR /&gt;scriptb var1=value1 var2=value2&lt;BR /&gt;&lt;BR /&gt;and in scriptb:&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;eval $@&lt;BR /&gt;print $var1&lt;BR /&gt;print $var2&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
    <pubDate>Wed, 04 Apr 2007 05:44:43 GMT</pubDate>
    <dc:creator>Peter Nikitka</dc:creator>
    <dc:date>2007-04-04T05:44:43Z</dc:date>
    <item>
      <title>Search and Display only searched string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975038#M758757</link>
      <description>Dear All,&lt;BR /&gt;I have two questions.&lt;BR /&gt;1)How can i display only searched string from files? E.g i have few files, i want to search file contents and if any file having string "Hello" on file contents then Hello needs to be put on display, no the entire line which of hello.&lt;BR /&gt;&lt;BR /&gt;2) I have one shell script which is calling to other shell script. How can i pass environment and user variables value to called shell script? &lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;TK</description>
      <pubDate>Wed, 04 Apr 2007 04:42:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975038#M758757</guid>
      <dc:creator>Tapas Jha</dc:creator>
      <dc:date>2007-04-04T04:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Search and Display only searched string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975039#M758758</link>
      <description>TK,&lt;BR /&gt;1. Why ? The whole idea of grep is to find the string and give you a reference on where to find it in the file. If you just want to know :&lt;BR /&gt;how often the string appears &lt;BR /&gt;use the -c option&lt;BR /&gt;whether the string appears&lt;BR /&gt;use the -l option&lt;BR /&gt;&lt;BR /&gt;2. It depends on how you call the other script:&lt;BR /&gt;&lt;BR /&gt;$ cat a.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;test="hello"&lt;BR /&gt;export test&lt;BR /&gt;. ./b.sh&lt;BR /&gt;&lt;BR /&gt;$ cat b.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;echo $test&lt;BR /&gt;&lt;BR /&gt;$ ./a.sh&lt;BR /&gt;hello&lt;BR /&gt;$ &lt;BR /&gt;&lt;BR /&gt;Or you can pass as parameter:&lt;BR /&gt;$ cat a.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;test="hello"&lt;BR /&gt;./b.sh "$test"&lt;BR /&gt;&lt;BR /&gt;$ cat b.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;echo $&lt;BR /&gt;&lt;BR /&gt;$ ./a.sh&lt;BR /&gt;hello&lt;BR /&gt;$ &lt;BR /&gt;&lt;BR /&gt;Please note the difference in calling ". "&lt;BR /&gt;&lt;BR /&gt;Please also read:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/helptips.do?#33" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/helptips.do?#33&lt;/A&gt; on how to reward any useful answers given to your questions.&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Apr 2007 04:57:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975039#M758758</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-04-04T04:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Search and Display only searched string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975040#M758759</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;1] in ur 1st question, I don't understand what&lt;BR /&gt;exactly u want do do by only displaying&lt;BR /&gt;searched word 'Hello' and not the entire&lt;BR /&gt;string contailing 'Hello' ('*Hello*'). Pl.&lt;BR /&gt;elaborate on this.&lt;BR /&gt;&lt;BR /&gt;2] U can export variables in caller script&lt;BR /&gt;say script1.sh, then only these variables will&lt;BR /&gt;be available in called script say script2.sh&lt;BR /&gt;and subsequent called scripts called from script1&lt;BR /&gt;eg.&lt;BR /&gt;&lt;BR /&gt;script1.sh&lt;BR /&gt;-------------&lt;BR /&gt;export var1=xyz&lt;BR /&gt;export var2=abc&lt;BR /&gt;&lt;BR /&gt;sh script2.sh&lt;BR /&gt;--------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;script2.sh&lt;BR /&gt;---------------&lt;BR /&gt;echo ${var1}&lt;BR /&gt;&lt;BR /&gt;sh script3.sh&lt;BR /&gt;-----------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;script3.sh&lt;BR /&gt;--------------&lt;BR /&gt;echo ${var2}&lt;BR /&gt;--------------&lt;BR /&gt;&lt;BR /&gt;This way u can pass env. and variables to&lt;BR /&gt;called script.</description>
      <pubDate>Wed, 04 Apr 2007 05:35:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975040#M758759</guid>
      <dc:creator>SANTOSH S. MHASKAR</dc:creator>
      <dc:date>2007-04-04T05:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Search and Display only searched string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975041#M758760</link>
      <description>As Peter says, why would you want to only print the string you were searching??&lt;BR /&gt;&lt;BR /&gt;If you really want to do this and don't want the -c or -l output, you can use:&lt;BR /&gt;$ grep -q Hello file1 ... &amp;amp;&amp;amp; echo "Hello"&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Peter: Please note the difference in calling ". "&lt;BR /&gt;&lt;BR /&gt;Why did you call this out (sourcing) and then went ahead and exported the variable?&lt;BR /&gt;You don't need to do that, nor do you need the #!.</description>
      <pubDate>Wed, 04 Apr 2007 05:38:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975041#M758760</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-04-04T05:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Search and Display only searched string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975042#M758761</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;1)&lt;BR /&gt;if fgrep -q "string" file1 file2 ...&lt;BR /&gt;then print "string"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;2) More than one possibility:&lt;BR /&gt;- You can export the variables in scripta and use them in scriptb ...:&lt;BR /&gt;scripta:&lt;BR /&gt;export var1=value1&lt;BR /&gt;export var2=value2&lt;BR /&gt;...&lt;BR /&gt;scriptb&lt;BR /&gt;&lt;BR /&gt;... and in scriptb just use that varible, but check the varibles first:&lt;BR /&gt;[ -n "$var1" ] || print -u2 var1 empty&lt;BR /&gt;...&lt;BR /&gt;- a 'short hand' export depends on the way you set your variables; this is possible as well in scripta:&lt;BR /&gt;var1=value1 var2=value2 scriptb&lt;BR /&gt;&lt;BR /&gt;- you can provide the variables as parameters to scriptb:&lt;BR /&gt;scriptb var1=value1 var2=value2&lt;BR /&gt;&lt;BR /&gt;and in scriptb:&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;eval $@&lt;BR /&gt;print $var1&lt;BR /&gt;print $var2&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 04 Apr 2007 05:44:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975042#M758761</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-04-04T05:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Search and Display only searched string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975043#M758762</link>
      <description>Dear Tapas,&lt;BR /&gt;&lt;BR /&gt;grep -F -x string filename &lt;BR /&gt;will print the exact string if the string is a single line.&lt;BR /&gt;&lt;BR /&gt;If it is a mulit word line (line with more than a word); then the grep will print the whole line with the string.&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;Local and global variables are both defined using the syntax &lt;BR /&gt;&lt;BR /&gt;VARIABLE="Some string"&lt;BR /&gt;&lt;BR /&gt;VAR=14&lt;BR /&gt;&lt;BR /&gt;By default these variables are local. To make them global (so that child processes will inherit them) use the command &lt;BR /&gt;&lt;BR /&gt;export VARIABLE&lt;BR /&gt;&lt;BR /&gt;This adds the variable to the process environment.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Rasheed Tamton.</description>
      <pubDate>Wed, 04 Apr 2007 08:05:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-and-display-only-searched-string/m-p/3975043#M758762</guid>
      <dc:creator>Rasheed Tamton</dc:creator>
      <dc:date>2007-04-04T08:05:55Z</dc:date>
    </item>
  </channel>
</rss>

