<?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 Awk inside for loop in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577737#M831622</link>
    <description>Hi Guys,&lt;BR /&gt;&lt;BR /&gt;I have a text file that look like this:&lt;BR /&gt;&lt;BR /&gt;20050605&lt;BR /&gt;&lt;BR /&gt;00  qq&lt;BR /&gt;01  ss&lt;BR /&gt;02  aa&lt;BR /&gt;03  rr&lt;BR /&gt;&lt;BR /&gt;Now, i want to make it in this format...&lt;BR /&gt;&lt;BR /&gt;20050605  00  qq&lt;BR /&gt;20050605  01  ss&lt;BR /&gt;20050605  02  aa&lt;BR /&gt;20050605  03  rr&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;using awk i was able to produce it:&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;        NF == 1 { tab = $1 ; next }&lt;BR /&gt;        NF == 2 { print tab , $0 } ' filename&lt;BR /&gt;&lt;BR /&gt;but when i put inside a loop im only getting this result:&lt;BR /&gt;&lt;BR /&gt;00  qq&lt;BR /&gt;01  ss&lt;BR /&gt;02  aa&lt;BR /&gt;03  rr&lt;BR /&gt;&lt;BR /&gt;the other field is gone..i need to run it inside a for loop since i have mutiple files to convert and this is what i used:&lt;BR /&gt;&lt;BR /&gt;for sgry in *.log&lt;BR /&gt;do&lt;BR /&gt;awk '&lt;BR /&gt;        NF == 1 { tab = $1 ; next }&lt;BR /&gt;        NF == 2 { print tab , $0 } ' $sgry &amp;gt; new.tmp&lt;BR /&gt;mv new.tmp $sgry&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;is there a better way to do it?&lt;BR /&gt;</description>
    <pubDate>Thu, 07 Jul 2005 04:53:20 GMT</pubDate>
    <dc:creator>Allan Umandap</dc:creator>
    <dc:date>2005-07-07T04:53:20Z</dc:date>
    <item>
      <title>Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577737#M831622</link>
      <description>Hi Guys,&lt;BR /&gt;&lt;BR /&gt;I have a text file that look like this:&lt;BR /&gt;&lt;BR /&gt;20050605&lt;BR /&gt;&lt;BR /&gt;00  qq&lt;BR /&gt;01  ss&lt;BR /&gt;02  aa&lt;BR /&gt;03  rr&lt;BR /&gt;&lt;BR /&gt;Now, i want to make it in this format...&lt;BR /&gt;&lt;BR /&gt;20050605  00  qq&lt;BR /&gt;20050605  01  ss&lt;BR /&gt;20050605  02  aa&lt;BR /&gt;20050605  03  rr&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;using awk i was able to produce it:&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;        NF == 1 { tab = $1 ; next }&lt;BR /&gt;        NF == 2 { print tab , $0 } ' filename&lt;BR /&gt;&lt;BR /&gt;but when i put inside a loop im only getting this result:&lt;BR /&gt;&lt;BR /&gt;00  qq&lt;BR /&gt;01  ss&lt;BR /&gt;02  aa&lt;BR /&gt;03  rr&lt;BR /&gt;&lt;BR /&gt;the other field is gone..i need to run it inside a for loop since i have mutiple files to convert and this is what i used:&lt;BR /&gt;&lt;BR /&gt;for sgry in *.log&lt;BR /&gt;do&lt;BR /&gt;awk '&lt;BR /&gt;        NF == 1 { tab = $1 ; next }&lt;BR /&gt;        NF == 2 { print tab , $0 } ' $sgry &amp;gt; new.tmp&lt;BR /&gt;mv new.tmp $sgry&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;is there a better way to do it?&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2005 04:53:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577737#M831622</guid>
      <dc:creator>Allan Umandap</dc:creator>
      <dc:date>2005-07-07T04:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577738#M831623</link>
      <description>You can do it as,&lt;BR /&gt;&lt;BR /&gt;# awk '/20050605/ { var=$1; getline;getline;} { print var" "$0 }' testfile&lt;BR /&gt;20050605 00 qq&lt;BR /&gt;20050605 01 ss&lt;BR /&gt;20050605 02 aa&lt;BR /&gt;20050605 03 rr&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;getline;getline is used to move 20050605,' ' line.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Thu, 07 Jul 2005 05:13:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577738#M831623</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-07T05:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577739#M831624</link>
      <description>One technique would be the following:&lt;BR /&gt;&lt;BR /&gt;# Script Starts here&lt;BR /&gt;####################&lt;BR /&gt;exec 4&amp;lt;$1&lt;BR /&gt;read -ru4 first&lt;BR /&gt;while read -ru4 f1 f2&lt;BR /&gt;do&lt;BR /&gt;echo $first $f1 $f2&lt;BR /&gt;done&lt;BR /&gt;# Script Ends Here&lt;BR /&gt;###################&lt;BR /&gt;&lt;BR /&gt;Store above script in a file "myscript"&lt;BR /&gt;and run at commandline as:&lt;BR /&gt;# ./myscript testfile_name&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2005 05:17:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577739#M831624</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-07-07T05:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577740#M831625</link>
      <description>Just try simply as,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; for file in `ls *.log`&lt;BR /&gt; do&lt;BR /&gt;&lt;BR /&gt;   awk '/20050605/ { var=$1; getline;getline;} { print var" "$0 }' $file &amp;gt; tmpfile&lt;BR /&gt;   mv tmpfile $file&lt;BR /&gt; &lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Thu, 07 Jul 2005 05:23:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577740#M831625</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-07T05:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577741#M831626</link>
      <description>sorry again. You can try as,&lt;BR /&gt;&lt;BR /&gt;for file in *.log&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  awk '{ if ( NR == 1) { var=$1;} if ( $0 != "" &amp;amp;&amp;amp; NF != 1 ) { print var" "$0 }}' $file &amp;gt; tmpfile&lt;BR /&gt;  mv tmpfile $file&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Thu, 07 Jul 2005 05:26:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577741#M831626</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-07T05:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577742#M831627</link>
      <description>Hi Allan, &lt;BR /&gt;&lt;BR /&gt;Can you try like this?&lt;BR /&gt;&lt;BR /&gt;ls *.log &amp;gt;test&lt;BR /&gt;for sgry in `cat test`&lt;BR /&gt;do&lt;BR /&gt;awk '&lt;BR /&gt;NF == 1 { tab = $1 ; next }&lt;BR /&gt;NF == 2 { print tab , $0 } ' $sgry &amp;gt; new.tmp&lt;BR /&gt;mv new.tmp $sgry&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Shyjith</description>
      <pubDate>Thu, 07 Jul 2005 05:33:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577742#M831627</guid>
      <dc:creator>Shyjith P K</dc:creator>
      <dc:date>2005-07-07T05:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577743#M831628</link>
      <description>Hi,&lt;BR /&gt;yet another solution&lt;BR /&gt;awk 'BEGIN { getline; var=$0 ; getline } { print var" "$0 }' file&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2005 05:41:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577743#M831628</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-07-07T05:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577744#M831629</link>
      <description>hi guys...i already sold my problem thanks for all your help..however i have another question before i close this thread...&lt;BR /&gt;&lt;BR /&gt;The 20050607 is actually the current date yyyymmdd, can anybody show me how to make my output like this:&lt;BR /&gt;&lt;BR /&gt;Jun07 00 aa&lt;BR /&gt;Jun07 01 bb&lt;BR /&gt;Jun07 02 cc&lt;BR /&gt;Jun07 03 dd&lt;BR /&gt;Jun07 04 ee&lt;BR /&gt;&lt;BR /&gt;tnx...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2005 05:44:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577744#M831629</guid>
      <dc:creator>Allan Umandap</dc:creator>
      <dc:date>2005-07-07T05:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577745#M831630</link>
      <description>Try as,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for file in *.log&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;awk '{ if ( $0 != "" &amp;amp;&amp;amp; NF != 1 ) { print var" "$0 }}' var="Jul 07" $file &amp;gt; tmpfile&lt;BR /&gt;mv tmpfile $file&lt;BR /&gt;&lt;BR /&gt;done</description>
      <pubDate>Thu, 07 Jul 2005 05:51:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577745#M831630</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-07T05:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577746#M831631</link>
      <description>Hi,&lt;BR /&gt;Maybe a task for Clay Stephenssons "date hammer".&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://mirrors.develooper.com/hpux/caljd-2.2.pl" target="_blank"&gt;http://mirrors.develooper.com/hpux/caljd-2.2.pl&lt;/A&gt;</description>
      <pubDate>Thu, 07 Jul 2005 06:04:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577746#M831631</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-07-07T06:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Awk inside for loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577747#M831632</link>
      <description>sorry. If there is no space between month and date then,&lt;BR /&gt;&lt;BR /&gt;you can easily do it as,&lt;BR /&gt;&lt;BR /&gt;## CODE ###&lt;BR /&gt;for file in *.log&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;awk '{ if ( $0 != "" &amp;amp;&amp;amp; NF != 1 ) { print var" "$0 }}' var=`date +'%a%d'` $file &amp;gt; tmpfile&lt;BR /&gt;mv tmpfile $file&lt;BR /&gt;&lt;BR /&gt;done</description>
      <pubDate>Thu, 07 Jul 2005 06:11:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-inside-for-loop/m-p/3577747#M831632</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-07T06:11:51Z</dc:date>
    </item>
  </channel>
</rss>

