<?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 pattern from a file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386567#M706428</link>
    <description>Rahul,&lt;BR /&gt;&lt;BR /&gt; We can use hein's method of perl or simply as,&lt;BR /&gt;&lt;BR /&gt;$ awk '{ for (i=1;i&amp;lt;=NF;i++) if ($i=="Status:40") print $i }' anandh&lt;BR /&gt;Status:40&lt;BR /&gt;&lt;BR /&gt;Your input file need not be separated with Field separator : there.&lt;BR /&gt;&lt;BR /&gt;If you want to do with file separator : then,&lt;BR /&gt;&lt;BR /&gt;$ awk -F "[ :]" '{ for ( i=1; i&amp;lt;=NF; i++ ) if ( $i == "Status" &amp;amp;&amp;amp; $(i+1) == 40 ) print $i":"$(i+1) }' &lt;INPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;Status:40&lt;BR /&gt;&lt;BR /&gt;You can this users question and answers to know about awk programming as,&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA1196931&amp;amp;forumId=1" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA1196931&amp;amp;forumId=1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;&lt;/INPUTFILE&gt;</description>
    <pubDate>Fri, 22 Oct 2004 01:17:59 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2004-10-22T01:17:59Z</dc:date>
    <item>
      <title>Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386559#M706420</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have to search a particular pattern in a file and extract only the pattern and the word that follows the pattern separated with colon. For example if the file contains a line&lt;BR /&gt;&lt;BR /&gt;....................abc : def...............&lt;BR /&gt;&lt;BR /&gt;I want to pick only "abc : def" from the line.&lt;BR /&gt;&lt;BR /&gt;Can anyone please help me out in this issue.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Sep 2004 18:18:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386559#M706420</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2004-09-24T18:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386560#M706421</link>
      <description>Try this&lt;BR /&gt;&lt;BR /&gt;  grep " abc :" inputfile | sed 's/.*\( abc :\)\( .* \).*/\1\2/'&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Sep 2004 18:25:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386560#M706421</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-24T18:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386561#M706422</link>
      <description>Or with perl:&lt;BR /&gt;&lt;BR /&gt;perl -ne 'print "$1\n" if (/(abc :\s+\w+)/)' inputfile&lt;BR /&gt;&lt;BR /&gt;-ne = loop over input file and program to follow'&lt;BR /&gt;$1 = matching text remembered between parentheses.&lt;BR /&gt;abc : = primary mathc string&lt;BR /&gt;\s+\w+ = secondary match = some white space followed by one or more 'word' characters (a-z,A-Z,0-9,_)&lt;BR /&gt;&lt;BR /&gt;You may need to define more clearly what a word means to you if this does not work.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Sep 2004 21:30:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386561#M706422</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-09-24T21:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386562#M706423</link>
      <description>We can do this with sed / perl there. awk will need more programming there. &lt;BR /&gt;&lt;BR /&gt;Simply with sed as,&lt;BR /&gt;$ cat file.1&lt;BR /&gt;test for now abc : def okie&lt;BR /&gt;bye for now&lt;BR /&gt;test abc : def over&lt;BR /&gt;$ sed -e '/abc : def/!d;s/.*\(abc : def\).*/\1/' file.1&lt;BR /&gt;abc : def&lt;BR /&gt;abc : def&lt;BR /&gt;&lt;BR /&gt;It will check /abc : def/ there and delete others and try to print only that pattern in the selected line.</description>
      <pubDate>Sat, 25 Sep 2004 01:07:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386562#M706423</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-25T01:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386563#M706424</link>
      <description>Rahul,&lt;BR /&gt;if there is only one colon per line then this should also work.&lt;BR /&gt;# export patt="abc:"&lt;BR /&gt;# cat filename | grep $patt | cut -d ":" -f2&lt;BR /&gt;&lt;BR /&gt;This will display all the words followed by pattern: &lt;BR /&gt;&lt;BR /&gt;Hope that helps.&lt;BR /&gt;Regards,</description>
      <pubDate>Sat, 25 Sep 2004 03:05:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386563#M706424</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-09-25T03:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386564#M706425</link>
      <description>&lt;BR /&gt;We can do with awk program as,&lt;BR /&gt;&lt;BR /&gt;Is your pattern abc&lt;SPACE&gt;: then,&lt;BR /&gt;awk '{ for ( i=1; i&amp;lt;=NF; i++ ) if ( $i == "abc" &amp;amp;&amp;amp; $(i+1) == ":" ) print $i" "$(i+1)" "$(i+2) }' &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;If abc: .. then,&lt;BR /&gt;awk '{ for ( i=1; i&amp;lt;=NF; i++ ) if ( $i == "abc:" ) print $i" "$(i+1) }' &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FILENAME&gt;&lt;/FILENAME&gt;&lt;/SPACE&gt;</description>
      <pubDate>Sat, 25 Sep 2004 05:21:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386564#M706425</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-25T05:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386565#M706426</link>
      <description>Hi MuthuKumar,&lt;BR /&gt;&lt;BR /&gt;I tried using your awk solution for the line in the attached file to get the pattern 'Status:40' but it did not return any values.&lt;BR /&gt;&lt;BR /&gt;Can you please look into it.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Oct 2004 17:28:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386565#M706426</guid>
      <dc:creator>Anand_30</dc:creator>
      <dc:date>2004-10-21T17:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386566#M706427</link>
      <description>Rahul,&lt;BR /&gt;&lt;BR /&gt;[In the future you may want to startup you own topic, referecing back to the original topic]&lt;BR /&gt;&lt;BR /&gt;The solution Muthukumar proposes hinges on a space seperating the search target from the value target. Your file does nto have a space. We can tweak the solution to allow for both spaces and colons to be a seperator:&lt;BR /&gt;&lt;BR /&gt;awk -F "[ :]" '{ for ( i=1; i&amp;lt;=NF; i++ ) if ( $i == "Status" ) print $i" "$(i+1) }' inputfile&lt;BR /&gt;&lt;BR /&gt;Personally I find think my perl solution, just using a regular expression is more elegant:&lt;BR /&gt;&lt;BR /&gt;perl -ne 'print "$1\n" if (/(Status:\w+)/)' inputfile&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If neither of these suggestion solve your problem, then you need to open your own topic and explain exactly (in words) what the search pattern looks. For example: "the word "Status", followed immediatly with a colon and a numeric value".&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Oct 2004 20:54:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386566#M706427</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-10-21T20:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386567#M706428</link>
      <description>Rahul,&lt;BR /&gt;&lt;BR /&gt; We can use hein's method of perl or simply as,&lt;BR /&gt;&lt;BR /&gt;$ awk '{ for (i=1;i&amp;lt;=NF;i++) if ($i=="Status:40") print $i }' anandh&lt;BR /&gt;Status:40&lt;BR /&gt;&lt;BR /&gt;Your input file need not be separated with Field separator : there.&lt;BR /&gt;&lt;BR /&gt;If you want to do with file separator : then,&lt;BR /&gt;&lt;BR /&gt;$ awk -F "[ :]" '{ for ( i=1; i&amp;lt;=NF; i++ ) if ( $i == "Status" &amp;amp;&amp;amp; $(i+1) == 40 ) print $i":"$(i+1) }' &lt;INPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;Status:40&lt;BR /&gt;&lt;BR /&gt;You can this users question and answers to know about awk programming as,&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA1196931&amp;amp;forumId=1" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA1196931&amp;amp;forumId=1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;&lt;/INPUTFILE&gt;</description>
      <pubDate>Fri, 22 Oct 2004 01:17:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386567#M706428</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-10-22T01:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386568#M706429</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Both the solution works, but I have a new requirement. I have a file with multiple lines and I need to search for the pattern in the file. Display the pattern for whichever lines the pattern is found and display a blank for the lines where the pattern a not located. For example:&lt;BR /&gt;&lt;BR /&gt;If the input is&lt;BR /&gt;&lt;BR /&gt;..............Status:30.................&lt;BR /&gt;..............Status:40...................&lt;BR /&gt;..........................................&lt;BR /&gt;............................................&lt;BR /&gt;..............Status:80.....................&lt;BR /&gt;&lt;BR /&gt;The output should be:&lt;BR /&gt;&lt;BR /&gt;Status:30&lt;BR /&gt;Status:40&lt;BR /&gt;blank&lt;BR /&gt;blank&lt;BR /&gt;Status:80&lt;BR /&gt;&lt;BR /&gt;Can you please help me.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Oct 2004 17:21:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386568#M706429</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2004-10-22T17:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Search pattern from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386569#M706430</link>
      <description>&lt;BR /&gt;Easy... You can figure this out with a little bit of perl/regexpr/grep/sed/awk learning.&lt;BR /&gt;&lt;BR /&gt;perl -pe '$_=(/(Status:\w+)/)?"$1\n":"\n"' input_file&lt;BR /&gt;&lt;BR /&gt;This tells perl to&lt;BR /&gt;-pe = Loop through the file and print $_ for each line.&lt;BR /&gt;(/../) = Look for "Status:" followed by a word (no spaces).&lt;BR /&gt;$_ = ()?..:.. = If matched assign match to $_ otherwise assign empty string.&lt;BR /&gt;&lt;BR /&gt;btw...&lt;BR /&gt;&lt;BR /&gt;I wrote "In the future you may want to startup you own topic, referecing back to the original topic" because you used a different author name (Anand).&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Oct 2004 21:54:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-pattern-from-a-file/m-p/3386569#M706430</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-10-22T21:54:05Z</dc:date>
    </item>
  </channel>
</rss>

