<?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: Match a field and print the line in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432556#M707435</link>
    <description>Yes. We can do with awk as,&lt;BR /&gt;&lt;BR /&gt;awk -F "|" '{ if ( $8 == 11) print $0 }' &lt;INPUTFILENAME&gt; &amp;gt; &lt;OUTPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;Problem in your try is, you have matched one line's 8th element but print NEXT line there.&lt;BR /&gt;&lt;BR /&gt;In next try,&lt;BR /&gt;try as,&lt;BR /&gt;&lt;BR /&gt;while read line; do&lt;BR /&gt;&lt;BR /&gt;  val=`echo $line | cut -d"|" -f8`&lt;BR /&gt;  if [ $val -eq 11 ] ; then&lt;BR /&gt;    echo $line&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; &lt;INPUTFILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;/INPUTFILENAME&gt;&lt;/OUTPUTFILE&gt;&lt;/INPUTFILENAME&gt;</description>
    <pubDate>Mon, 29 Nov 2004 23:10:24 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2004-11-29T23:10:24Z</dc:date>
    <item>
      <title>Match a field and print the line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432551#M707430</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a file with about 10000 lines. I have to match the 8th field of each line with a value (say "11") and output the line to another file if the field matches the value. Each field in the file is delimited with "|". I tried using &lt;BR /&gt;&lt;BR /&gt;cat filename|awk -F "|" '{ if ($8 == 11 ) {getline; print $0}}&lt;BR /&gt;&lt;BR /&gt;and also &lt;BR /&gt;&lt;BR /&gt;cat filename | while read line&lt;BR /&gt;do&lt;BR /&gt;val=`cat -d"|" -f8 $line`&lt;BR /&gt;if [ $val -eq 11 ] ; then&lt;BR /&gt;echo $line&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Both did not work.&lt;BR /&gt;&lt;BR /&gt;Can anyone please help me doing this.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Anand.</description>
      <pubDate>Mon, 29 Nov 2004 20:23:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432551#M707430</guid>
      <dc:creator>Anand_30</dc:creator>
      <dc:date>2004-11-29T20:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Match a field and print the line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432552#M707431</link>
      <description>Does your second script really use "cat -d "|"&lt;BR /&gt;-f8 $line"?  Or is that just a typo in your post? &lt;BR /&gt;&lt;BR /&gt;You would want: val=`cut -d"|" -f8 $line`</description>
      <pubDate>Mon, 29 Nov 2004 20:35:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432552#M707431</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2004-11-29T20:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Match a field and print the line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432553#M707432</link>
      <description>You are making this too hard:&lt;BR /&gt;&lt;BR /&gt; awk -F '|' '{if ($8 == "11") print $0}' infilename &amp;gt; outfilename&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If you want to evaluate $8 as an integer you need to coerce the type and change the comparison to&lt;BR /&gt;if (($8 + 0) == 11)&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Nov 2004 21:47:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432553#M707432</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-11-29T21:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Match a field and print the line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432554#M707433</link>
      <description>try the following :&lt;BR /&gt;$cat test | awk -F  "|"  '$8 == 11  {print $0}'&lt;BR /&gt;or&lt;BR /&gt;val=$(cat -d  "|" -f8 $line)&lt;BR /&gt;&lt;BR /&gt;There are spaces in the field separators.</description>
      <pubDate>Mon, 29 Nov 2004 21:54:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432554#M707433</guid>
      <dc:creator>Yan Wong</dc:creator>
      <dc:date>2004-11-29T21:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Match a field and print the line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432555#M707434</link>
      <description>should be &lt;BR /&gt;cat filename |</description>
      <pubDate>Mon, 29 Nov 2004 22:15:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432555#M707434</guid>
      <dc:creator>Yan Wong</dc:creator>
      <dc:date>2004-11-29T22:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Match a field and print the line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432556#M707435</link>
      <description>Yes. We can do with awk as,&lt;BR /&gt;&lt;BR /&gt;awk -F "|" '{ if ( $8 == 11) print $0 }' &lt;INPUTFILENAME&gt; &amp;gt; &lt;OUTPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;Problem in your try is, you have matched one line's 8th element but print NEXT line there.&lt;BR /&gt;&lt;BR /&gt;In next try,&lt;BR /&gt;try as,&lt;BR /&gt;&lt;BR /&gt;while read line; do&lt;BR /&gt;&lt;BR /&gt;  val=`echo $line | cut -d"|" -f8`&lt;BR /&gt;  if [ $val -eq 11 ] ; then&lt;BR /&gt;    echo $line&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; &lt;INPUTFILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;/INPUTFILENAME&gt;&lt;/OUTPUTFILE&gt;&lt;/INPUTFILENAME&gt;</description>
      <pubDate>Mon, 29 Nov 2004 23:10:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-a-field-and-print-the-line/m-p/3432556#M707435</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-11-29T23:10:24Z</dc:date>
    </item>
  </channel>
</rss>

