<?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: scripting.. searching for a string in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876110#M279293</link>
    <description>cat file1|awk 'FS="\"" {print $4 " " $6}'</description>
    <pubDate>Wed, 11 Oct 2006 11:11:46 GMT</pubDate>
    <dc:creator>Yang Qin_1</dc:creator>
    <dc:date>2006-10-11T11:11:46Z</dc:date>
    <item>
      <title>scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876096#M279279</link>
      <description>admins,&lt;BR /&gt;&lt;BR /&gt;each line in a file contains four strings within double quotes("").&lt;BR /&gt;&lt;BR /&gt;like this:&lt;BR /&gt;An "Apple" "a" day "keeps" the "doctor" away.&lt;BR /&gt;&lt;BR /&gt;i need to grep for this this four strings in each line.&lt;BR /&gt;&lt;BR /&gt;PS:i understand the need to learn GOOD scriping.&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Oct 2006 15:14:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876096#M279279</guid>
      <dc:creator>inventsekar_1</dc:creator>
      <dc:date>2006-10-06T15:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876097#M279280</link>
      <description>An "Apple" "a" day "keeps" the "doctor" away.&lt;BR /&gt;&lt;BR /&gt;IN this line i need to grep the four strings and put in a new file as:&lt;BR /&gt;&lt;BR /&gt;Apple a keeps doctor</description>
      <pubDate>Fri, 06 Oct 2006 15:32:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876097#M279280</guid>
      <dc:creator>inventsekar_1</dc:creator>
      <dc:date>2006-10-06T15:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876098#M279281</link>
      <description>Your are not specific enough but if the goal is to match the quoted strings in that order then:&lt;BR /&gt;&lt;BR /&gt;grep -E '"Apple".*"a".*"keeps".*"doctor"' &amp;lt; myfile&lt;BR /&gt;&lt;BR /&gt;Now if the order is not important then:&lt;BR /&gt;&lt;BR /&gt;grep -E '"Apple"' &amp;lt; myfile | grep '"a"' | grep '"keeps"' | grep -E '"doctor"'&lt;BR /&gt;&lt;BR /&gt;You can add a -i in addition to each -E to make grep's matchs case-insensitive. Note that the single-quotes are used to escape the double-quotes in your target strings.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Oct 2006 15:33:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876098#M279281</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-10-06T15:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876099#M279282</link>
      <description>sorry for that.&lt;BR /&gt;&lt;BR /&gt;i need to search for the four strings(each string will be inside "") in a line.&lt;BR /&gt;&lt;BR /&gt;sorry for the wrong example. &lt;BR /&gt;the strings are not constant. so i need to search for the strings inside "".</description>
      <pubDate>Fri, 06 Oct 2006 15:40:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876099#M279282</guid>
      <dc:creator>inventsekar_1</dc:creator>
      <dc:date>2006-10-06T15:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876100#M279283</link>
      <description>PS:i understand the need to learn GOOD scriping. &lt;BR /&gt;&lt;BR /&gt;In that case, you should change the question because the task as you now define it (with your second posting) is not a good use of grep. There are better tools for the task when you want to print only the target strings.&lt;BR /&gt;&lt;BR /&gt;typeset -i I=1&lt;BR /&gt;typeset -i N=$(grep -E '"Apple".*"a".*"keeps".*"doctor"' myfile | wc -l)&lt;BR /&gt;while [[ ${I} -le ${N} ]]&lt;BR /&gt;  do&lt;BR /&gt;    echo "Apple a day doctor" &amp;gt;&amp;gt; newfile&lt;BR /&gt;    ((I += 1))&lt;BR /&gt;  done&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Oct 2006 15:47:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876100#M279283</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-10-06T15:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876101#M279284</link>
      <description>And now we are on to yet another question. I think I will wait until you can phrase the question exactly because unless I'm quail hunting I don't like shooting at moving targets.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Oct 2006 15:49:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876101#M279284</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-10-06T15:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876102#M279285</link>
      <description>cat file1 |cut -d"\"" -f2,4,6,8|sed 's/\"/ /g'</description>
      <pubDate>Fri, 06 Oct 2006 15:50:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876102#M279285</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-10-06T15:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876103#M279286</link>
      <description># perl -nle'BEGIN{%h=map{$_=&amp;gt;1}qw(apple a keeps doctor)}$n=0;$n+=$h{lc$1}for/"(\w+)"/g;$n==4&amp;amp;&amp;amp;print' file&lt;BR /&gt;&lt;BR /&gt;Just a go.&lt;BR /&gt;Will print all lines in the file that has all 4 words "apple", "a", "keeps", and "doctor" quoted in any casing in any order.&lt;BR /&gt;&lt;BR /&gt;That what you want?&lt;BR /&gt;Probably can be done even shorter, but I don't wanna play golf right now&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Fri, 06 Oct 2006 15:59:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876103#M279286</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-10-06T15:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876104#M279287</link>
      <description>&lt;BR /&gt;&amp;gt;&amp;gt; PS:i understand the need to learn GOOD scriping.&lt;BR /&gt;&lt;BR /&gt;The single most critical part of good scripting it learn to get and capture a good problem statement. Exactly what needs to happen? What should not happen? which eventualities need to be protected against (defensive scripting!).&lt;BR /&gt;&lt;BR /&gt;I find that clear sample data, both input and output are critical in understanding the problem, the constraints of the solution, and as 'proof' that the script works.&lt;BR /&gt;&lt;BR /&gt;Now as far as the task on hand...&lt;BR /&gt;&lt;BR /&gt;What does 'grep for this this four strings' mean?&lt;BR /&gt;&lt;BR /&gt;Do you want to grep for a single string in any of those for 'fields' but not outside?&lt;BR /&gt;&lt;BR /&gt;So if the data was&lt;BR /&gt;&lt;BR /&gt;1: An "Apple" "a" day "keeps" the "doctor" away.&lt;BR /&gt;2: An "pear" in "the" night is "just" "right".&lt;BR /&gt;&lt;BR /&gt;Now when you 'grep' for 'the', should find the second line but not the first?&lt;BR /&gt;&lt;BR /&gt;This awk will do that... just barely:&lt;BR /&gt;&lt;BR /&gt;&amp;gt;awk -F\" -v x=the "{ if (index($2 $4 $6 $8, x) ) { print }}" tmp.txt&lt;BR /&gt;&lt;BR /&gt;How does that work?&lt;BR /&gt;&lt;BR /&gt;If a double quote is made the 'split' character with -F, then every other variable will be a quoted word: 2,4,6,8...&lt;BR /&gt;"$2 $4 $6 $6" glues them together, and if we find a non-zero return then the string pushed in x must be in there.&lt;BR /&gt;&lt;BR /&gt;Now a sample contraint question:&lt;BR /&gt;&lt;BR /&gt;In the code about 'theju' will match "the" "just" is that acceptable?&lt;BR /&gt;&lt;BR /&gt;If not then we either have to look in the individual strings:&lt;BR /&gt;&lt;BR /&gt;&amp;gt;awk -F\" -v x=the "{if (index($2,x) + index($4,x) + index($6,x) + index($8,x)) { print }}" tmp.txt&lt;BR /&gt;&lt;BR /&gt;or use same acceptable seperator (here *), passed in as a variable to keep it flexible.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;awk -F\" -v x=theju -v a=* "{ if (index($2 a $4 a $6 a $8, x) ){print} }" tmp.txt&lt;BR /&gt;&lt;BR /&gt;so many solutions...&lt;BR /&gt;so many gotchas.&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Oct 2006 16:01:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876104#M279287</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-10-06T16:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876105#M279288</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;use the quote as delimiter and output the even numbered fields:&lt;BR /&gt;&lt;BR /&gt;awk -F'"' 'NF==9 {for(i=2;i&lt;NF&gt;&lt;/NF&gt;&lt;BR /&gt;will do this.&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Fri, 06 Oct 2006 16:03:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876105#M279288</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-10-06T16:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876106#M279289</link>
      <description>As said by Hein and Peter the trick is to print the even fields...here's my script:&lt;BR /&gt;&lt;BR /&gt;# awk -F\" '{for(i=1;i&amp;lt;=NF;++i){if(!(i%2)) printf("%s ",$i)} print ""}' infile&lt;BR /&gt;&lt;BR /&gt;~hope it helps</description>
      <pubDate>Fri, 06 Oct 2006 17:39:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876106#M279289</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-10-06T17:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876107#M279290</link>
      <description>Thanks goes to all. sorry for the delayed response.&lt;BR /&gt;&lt;BR /&gt;i thought to edit the first post thru Moderator intervention, but when others will read after sometime, they will not come to know what happend..so i am leaving that as it is.&lt;BR /&gt;&lt;BR /&gt;now again, the REAL question is:&lt;BR /&gt;my file contains line like this:&lt;BR /&gt;&lt;BR /&gt;firstLine: CONSTANT="no" NAME="abcde" initialValue="1" NAME="abcde"&lt;BR /&gt;secondLine: CONSTANT="no" NAME="fghij" initialValue="0" NAME="fghij"&lt;BR /&gt;&lt;BR /&gt;1.)each line contains four strings &lt;BR /&gt;2.)out of which first string is always "no" &lt;BR /&gt;3.)second string and  fourth string are same.&lt;BR /&gt;4.)third string can take only one of two values (0 or 1).&lt;BR /&gt;&lt;BR /&gt;now, from this two lines:&lt;BR /&gt;CONSTANT="no" NAME="abcde" initialValue="1" NAME="abcde"&lt;BR /&gt;CONSTANT="no" NAME="fghij" initialValue="0" NAME="fghij"&lt;BR /&gt;&lt;BR /&gt;i need to create a file like this:&lt;BR /&gt;abcde 1&lt;BR /&gt;fghij 0&lt;BR /&gt;&lt;BR /&gt;note that: i cant "cut" since in the line starting there may be one space or two spaces or a tab.&lt;BR /&gt;&lt;BR /&gt;hope u understand it clearly now.&lt;BR /&gt;it may be simple for GOOD admins.</description>
      <pubDate>Wed, 11 Oct 2006 09:58:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876107#M279290</guid>
      <dc:creator>inventsekar_1</dc:creator>
      <dc:date>2006-10-11T09:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876108#M279291</link>
      <description>Quick and dirty. There is probably a way to remove the quotes in awk so you don't have to fork a second sed process:&lt;BR /&gt;&lt;BR /&gt;cat file | awk -F"[ =]" '{print $4, $6}' | sed -e 's/"//g'</description>
      <pubDate>Wed, 11 Oct 2006 10:22:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876108#M279291</guid>
      <dc:creator>Jonathan Fife</dc:creator>
      <dc:date>2006-10-11T10:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876109#M279292</link>
      <description>You *CAN* use cut:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 108 &amp;gt; cat xx.dta&lt;BR /&gt;CONSTANT="no" NAME="abcde" initialValue="1" NAME="abcde"&lt;BR /&gt;CONSTANT="no" NAME="fghij" initialValue="0" NAME="fghij"&lt;BR /&gt;lt09:/home/merijn 109 &amp;gt; cut -d\" -f4,6 xx.dta&lt;BR /&gt;abcde"1&lt;BR /&gt;fghij"0&lt;BR /&gt;lt09:/home/merijn 110 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Or, *literally* applying that criteria:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 110 &amp;gt; perl -ne's/^.*?(NAME="([^"]+)").*?"([01])"\s+\1.*/$2\t$3/&amp;amp;&amp;amp;print' xx.dta&lt;BR /&gt;abcde   1&lt;BR /&gt;fghij   0&lt;BR /&gt;lt09:/home/merijn 111 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.merijn</description>
      <pubDate>Wed, 11 Oct 2006 10:39:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876109#M279292</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-10-11T10:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876110#M279293</link>
      <description>cat file1|awk 'FS="\"" {print $4 " " $6}'</description>
      <pubDate>Wed, 11 Oct 2006 11:11:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876110#M279293</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-10-11T11:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876111#M279294</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Using 'cat' in a pipeline to 'swk' is a waste of another process!  &lt;BR /&gt;&lt;BR /&gt;# cat file | awk 'FS="\"" {print $4 " " $6}'&lt;BR /&gt;&lt;BR /&gt;...should be:&lt;BR /&gt;&lt;BR /&gt;# awk 'FS="\"" {print $4 " " $6}' file&lt;BR /&gt;&lt;BR /&gt;...or, more succinctly:&lt;BR /&gt;&lt;BR /&gt;# awk 'FS="\"" {print $4,$6}' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Oct 2006 11:22:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876111#M279294</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-11T11:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876112#M279295</link>
      <description># awk -F\" '{print $4,$6}' infile&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Wed, 11 Oct 2006 11:26:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876112#M279295</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-10-11T11:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876113#M279296</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;and two chars shorter as James' and even working in gawk:&lt;BR /&gt;&lt;BR /&gt;awk -F'"' '{print $4,$6}' file&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 11 Oct 2006 11:34:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876113#M279296</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-10-11T11:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: scripting.. searching for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876114#M279297</link>
      <description>Hi Peter:&lt;BR /&gt;&lt;BR /&gt;Yeah, two characters shorter --- I like that better than mine!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 11 Oct 2006 11:44:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-searching-for-a-string/m-p/3876114#M279297</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-11T11:44:09Z</dc:date>
    </item>
  </channel>
</rss>

