<?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: Found a word in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680118#M102863</link>
    <description>You have managed to confuse me and I never solve a problem until I understand it.&lt;BR /&gt;&lt;BR /&gt;You said for input:&lt;BR /&gt;2/6 ARASW25 TOTO tutu&lt;BR /&gt;(ARASW26) 2/6 TOTO xyz 12/x&lt;BR /&gt;tutu yy uu 6/8 ARASW56 titi fff&lt;BR /&gt;&lt;BR /&gt;You want:&lt;BR /&gt;ARASW25&lt;BR /&gt;ARASW26&lt;BR /&gt;&lt;BR /&gt;Note that "(ARASW26)" does not start with "ARASW" but is included in the output; however, "ARASW56" does start with "ARASW" but is not included in the output.&lt;BR /&gt;&lt;BR /&gt;Grep will not do this but sed, perl, or awk can easily grab the field. You should also tell us whether "ARASW" appears at most once in any given line of input. If more than once then what should the output be? &lt;BR /&gt;"ARASW"</description>
    <pubDate>Mon, 28 Nov 2005 11:26:17 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2005-11-28T11:26:17Z</dc:date>
    <item>
      <title>Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680117#M102862</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;How to extract a word or a field in a file&lt;BR /&gt;depending on the position of another word, field ? &lt;BR /&gt;&lt;BR /&gt;variable:&lt;BR /&gt;MODPORT="2/6"&lt;BR /&gt;&lt;BR /&gt;here the text file :&lt;BR /&gt;2/6 ARASW25 TOTO tutu&lt;BR /&gt;(ARASW26) 2/6 TOTO xyz 12/x&lt;BR /&gt;tutu yy uu 6/8 ARASW56 titi fff&lt;BR /&gt;&lt;BR /&gt;with a command like:&lt;BR /&gt;grep $MODPORT fic | ....&lt;BR /&gt;&lt;BR /&gt;We want to extract only the words beginning&lt;BR /&gt;by "ARASW" with the variable "MODPORT":&lt;BR /&gt;             ARASW25&lt;BR /&gt;             ARASW26&lt;BR /&gt;&lt;BR /&gt;Thanks a lot.(if you understand my problem)</description>
      <pubDate>Mon, 28 Nov 2005 10:57:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680117#M102862</guid>
      <dc:creator>iranzo</dc:creator>
      <dc:date>2005-11-28T10:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680118#M102863</link>
      <description>You have managed to confuse me and I never solve a problem until I understand it.&lt;BR /&gt;&lt;BR /&gt;You said for input:&lt;BR /&gt;2/6 ARASW25 TOTO tutu&lt;BR /&gt;(ARASW26) 2/6 TOTO xyz 12/x&lt;BR /&gt;tutu yy uu 6/8 ARASW56 titi fff&lt;BR /&gt;&lt;BR /&gt;You want:&lt;BR /&gt;ARASW25&lt;BR /&gt;ARASW26&lt;BR /&gt;&lt;BR /&gt;Note that "(ARASW26)" does not start with "ARASW" but is included in the output; however, "ARASW56" does start with "ARASW" but is not included in the output.&lt;BR /&gt;&lt;BR /&gt;Grep will not do this but sed, perl, or awk can easily grab the field. You should also tell us whether "ARASW" appears at most once in any given line of input. If more than once then what should the output be? &lt;BR /&gt;"ARASW"</description>
      <pubDate>Mon, 28 Nov 2005 11:26:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680118#M102863</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-11-28T11:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680119#M102864</link>
      <description>grep $MODPORT fic | sed -e "s/^.*ARASW/ARASW/" -e "s/[^[:alnum:]].*//"&lt;BR /&gt;&lt;BR /&gt;(That's all on one line by the way.)&lt;BR /&gt;&lt;BR /&gt;Possibly, not sure if I understand your question fully.</description>
      <pubDate>Mon, 28 Nov 2005 11:29:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680119#M102864</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-11-28T11:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680120#M102865</link>
      <description>Oh, I see, you first want to find any line containing "2/6" but this is flawed as well. What about lines containing "12/6", "2/60", etc. Are the only characters which could surround your "ARASW", '(' and ')'?</description>
      <pubDate>Mon, 28 Nov 2005 11:30:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680120#M102865</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-11-28T11:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680121#M102866</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;grep can only handle entire lines (records) by itself. awk can handle words (fields) in addition to records&lt;BR /&gt;So you need to use a combination of grep &amp;amp; awk to do this.&lt;BR /&gt;&lt;BR /&gt;Rgds,&lt;BR /&gt;Jeff</description>
      <pubDate>Mon, 28 Nov 2005 11:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680121#M102866</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2005-11-28T11:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680122#M102867</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Perhaps this helps:&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/perl.pl&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;$x=shift;&lt;BR /&gt;$f=shift;&lt;BR /&gt;open( FH, "&amp;lt;", $f ) or die "Can't open $f: $!\n";&lt;BR /&gt;while (&lt;FH&gt;) {&lt;BR /&gt;    if (m%$x%go) {&lt;BR /&gt;        print "$`" if defined $`;&lt;BR /&gt;        print "$'" if defined $';&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Run as:&lt;BR /&gt;&lt;BR /&gt;# /tmp/perl.pl 2/6 file&lt;BR /&gt;&lt;BR /&gt;...where "2/6" is your MODPORT variable value and "file" is your input.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;/FH&gt;</description>
      <pubDate>Mon, 28 Nov 2005 11:31:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680122#M102867</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-11-28T11:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680123#M102868</link>
      <description>I'm going to post two things.  The first will pull the words that CONTAIN ARASW as follows.&lt;BR /&gt;&lt;BR /&gt;Create a file called pullit.awk and put the following lines in it:&lt;BR /&gt;&lt;BR /&gt;/ARASW/ {idx1=index($0,"ARASW");&lt;BR /&gt;         sbs1=substr($0,idx1);&lt;BR /&gt;         idx2=index(sbs1," ");&lt;BR /&gt;         if (idx2==0) {print sbs2;next;};&lt;BR /&gt;         print substr(sbs1,1,idx2);&lt;BR /&gt;         }&lt;BR /&gt;&lt;BR /&gt;Run the command:&lt;BR /&gt;&lt;BR /&gt;awk -f pullit.awk &amp;lt; inputfile&lt;BR /&gt;&lt;BR /&gt;Output will be:&lt;BR /&gt;&lt;BR /&gt;ARASW25 &lt;BR /&gt;ARASW26) &lt;BR /&gt;ARASW56 &lt;BR /&gt;</description>
      <pubDate>Mon, 28 Nov 2005 11:39:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680123#M102868</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2005-11-28T11:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680124#M102869</link>
      <description>Oops .. okay .. see that by re-reading this, I see that you also want the line to have the same value as $MODPORT.&lt;BR /&gt;&lt;BR /&gt;so here is what I would do.&lt;BR /&gt;&lt;BR /&gt;Create a file pullit.sh&lt;BR /&gt;&lt;BR /&gt;echo $MODPORT &amp;gt; useme&lt;BR /&gt;cat textfile &amp;gt;&amp;gt; useme&lt;BR /&gt;awk -f pullit.awk &amp;lt; useme&lt;BR /&gt;&lt;BR /&gt;Create another file called pullit.awk:&lt;BR /&gt;&lt;BR /&gt;NR==1 {checkvalue=$0;next;}&lt;BR /&gt;index($0,checkvalue)==0{next}&lt;BR /&gt;/ARASW/ {idx1=index($0,"ARASW");&lt;BR /&gt;         sbs1=substr($0,idx1);&lt;BR /&gt;         idx2=index(sbs1," ");&lt;BR /&gt;         if (idx2==0) {print sbs2;next;};&lt;BR /&gt;         print substr(sbs1,1,idx2);&lt;BR /&gt;         }&lt;BR /&gt;&lt;BR /&gt;This will yield:&lt;BR /&gt;ARASW25 &lt;BR /&gt;ARASW26)&lt;BR /&gt;&lt;BR /&gt;If you know that you will haev ARASW?? then you can use this for pullit.awk instead:&lt;BR /&gt;&lt;BR /&gt;NR==1 {checkvalue=$0;next;}&lt;BR /&gt;index($0,checkvalue)==0{next}&lt;BR /&gt;/ARASW/ {idx1=index($0,"ARASW");&lt;BR /&gt;         print substr($0,idx1,7);&lt;BR /&gt;         }&lt;BR /&gt;&lt;BR /&gt;This will yield:&lt;BR /&gt;&lt;BR /&gt;ARASW25&lt;BR /&gt;ARASW26&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Nov 2005 11:48:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680124#M102869</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2005-11-28T11:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680125#M102870</link>
      <description>How about the awk construct below:&lt;BR /&gt;&lt;BR /&gt;awk '$0~/2\/6/ {print substr($0,match($0,/ARASW/),7)}' &lt;INPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;cheers!&lt;/INPUTFILE&gt;</description>
      <pubDate>Mon, 28 Nov 2005 12:34:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680125#M102870</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-11-28T12:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680126#M102871</link>
      <description>Hi Iranzo:&lt;BR /&gt;&lt;BR /&gt;This gives you exactly what you described whether or not your "word" occurs before or after the 'MODPORT' variable's value.  It's a generalized script to show the word that preceeds or follows the token specified:&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/perl.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($x, $f, $part1, $part2, @flds);&lt;BR /&gt;$x=shift;&lt;BR /&gt;$f=shift;&lt;BR /&gt;open( FH, "&amp;lt;", $f ) or die "Can't open $f: $!\n";&lt;BR /&gt;while (&lt;FH&gt;) {&lt;BR /&gt;    if (m%$x%go) {&lt;BR /&gt;        ($part1 = $`) =~ s/[()]//g;&lt;BR /&gt;        ($part2 = $') =~ s/[()]//g;&lt;BR /&gt;        if ($part1 =~ m/\s+/) {&lt;BR /&gt;            print "$part1\n";&lt;BR /&gt;        } else {&lt;BR /&gt;            @flds = split / /, $part2;&lt;BR /&gt;            print "$flds[1]\n";     &lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;--cut--&lt;BR /&gt;&lt;BR /&gt;NOTE that the "word" that occurs before or after 'MODPORT' is printed.  Given your input, you will see your requested output.&lt;BR /&gt;&lt;BR /&gt;As before, run as:&lt;BR /&gt;&lt;BR /&gt;# MODPORT="2/6";/tmp/perl.pl ${MODPORT} filename&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/FH&gt;</description>
      <pubDate>Mon, 28 Nov 2005 15:12:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680126#M102871</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-11-28T15:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680127#M102872</link>
      <description>For Stephenson&lt;BR /&gt;&lt;BR /&gt;We just want lines containing 2/6&lt;BR /&gt;Surround ARASW the only characters&lt;BR /&gt;are ( and )&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 29 Nov 2005 04:04:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680127#M102872</guid>
      <dc:creator>iranzo</dc:creator>
      <dc:date>2005-11-29T04:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680128#M102873</link>
      <description>Do you want to grep the 2/6 pattern from a file and check for ARASW string enclosed with ()??&lt;BR /&gt;&lt;BR /&gt;# cat file1&lt;BR /&gt;2/6 ARASW25 TOTO tutu&lt;BR /&gt;(ARASW26) 2/6 TOTO xyz 12/x&lt;BR /&gt;tutu yy uu 6/8 ARASW56 titi fff&lt;BR /&gt;# grep "2/6" file1  | grep '^(ARASW[^ ]*)'&lt;BR /&gt;(ARASW26) 2/6 TOTO xyz 12/x&lt;BR /&gt;&lt;BR /&gt;If it is not the requirement revert with more details.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Tue, 29 Nov 2005 04:11:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680128#M102873</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-11-29T04:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680129#M102874</link>
      <description>Hi Iranzo:&lt;BR /&gt;&lt;BR /&gt;Please try the second solution I posted above.  Based on your input, in my opinion, it *does* give you exactly the output for which you asked.&lt;BR /&gt;&lt;BR /&gt;Cut-and-paste the script I posted in my *second* post, name it "perl.pl" and call it like:&lt;BR /&gt;&lt;BR /&gt;# ./perl.pl 2/6 yourfile&lt;BR /&gt;&lt;BR /&gt;The first argument (for example, 2/6, tells that you only want to find lines with this token in them.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Nov 2005 05:14:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680129#M102874</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-11-29T05:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680130#M102875</link>
      <description>Could not understand your requirement in the beginning:(&lt;BR /&gt;&lt;BR /&gt;# grep $MODPORT fic | awk '{ for (i=1;i&lt;NF&gt;&lt;/NF&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Tue, 29 Nov 2005 05:41:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680130#M102875</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-11-29T05:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680131#M102876</link>
      <description>Simpy as,&lt;BR /&gt;&lt;BR /&gt;sed -e "/2\/6/!d;s/.*\(ARASW[^) ]*\).*/\1/;" &lt;FILE&gt;&lt;BR /&gt;&lt;BR /&gt;hth.&lt;/FILE&gt;</description>
      <pubDate>Tue, 29 Nov 2005 05:54:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680131#M102876</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-11-29T05:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Found a word</title>
      <link>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680132#M102877</link>
      <description>Iranzo,&lt;BR /&gt;&lt;BR /&gt;Based on your reply here's the complete awk construct...&lt;BR /&gt;&lt;BR /&gt;# awk '$0~/ 2\/6 /||$0~/^2\/6 /||$0~/ 2\/6$/{print substr($0,match($0,/ARASW/),7)}' &lt;INFILE&gt;&lt;BR /&gt;&lt;BR /&gt;cheers!&lt;/INFILE&gt;</description>
      <pubDate>Tue, 29 Nov 2005 12:52:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/found-a-word/m-p/3680132#M102877</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-11-29T12:52:50Z</dc:date>
    </item>
  </channel>
</rss>

