<?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: While Loop Question? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513497#M681371</link>
    <description>Not entirely sure what you want, be here are some observations which may help.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; var=`grep "@foobar.com" file |wc -l`&lt;BR /&gt;if [$var &amp;gt; 1]&lt;BR /&gt;&lt;BR /&gt;Why pipe into 'wc -l' just use `grep -c ...`&lt;BR /&gt;&lt;BR /&gt;But since you do not care how many matches, why not just look at the return status&lt;BR /&gt;&lt;BR /&gt;Just use:&lt;BR /&gt;&lt;BR /&gt;grep -q ...&lt;BR /&gt;if [$? == 0 ] &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now a perl program like mine ,here presented as program, not one-liner or or JRF's, is the ideal place to not just look for a that target string anywhere but only where is it meaningful.&lt;BR /&gt;It too can return a status, based on having seen a proper Email or not:&lt;BR /&gt;&lt;BR /&gt;-----------------------------&lt;BR /&gt;$email_not_seen = 1; &lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  chomp; &lt;BR /&gt;  @words=split; &lt;BR /&gt;  $u=shift @words;&lt;BR /&gt;  $email_not_seen = 0 if $u =~ /\@foobar.com/;&lt;BR /&gt; &lt;BR /&gt;  print "&lt;USER name="\&amp;quot;$u\&amp;quot;"&gt;\n&lt;WORDS&gt;\n"; &lt;BR /&gt;  for (@words) {&lt;BR /&gt;    print "&lt;WORD&gt;$_&lt;/WORD&gt;\n"&lt;BR /&gt;  }&lt;BR /&gt;  print "&lt;/WORDS&gt;\n&lt;/USER&gt;\n"'&lt;BR /&gt;}&lt;BR /&gt;exit $email_not_seen&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Of course perl coudl also do somethinh like.. (untested):&lt;BR /&gt;&lt;BR /&gt;-----------------------------&lt;BR /&gt;$xml = 'interim.xml';&lt;BR /&gt;open XML  "&amp;gt;xml";&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  chomp; &lt;BR /&gt;  @words=split; &lt;BR /&gt;  $u=shift @words;&lt;BR /&gt;  $email_seen = ($u =~ /\@foobar.com/);&lt;BR /&gt; &lt;BR /&gt;  print XML "&lt;USER name="\&amp;quot;$u\&amp;quot;"&gt;\n&lt;WORDS&gt;\n"; &lt;BR /&gt;  for (@words) {&lt;BR /&gt;    print XML "&lt;WORD&gt;$_&lt;/WORD&gt;\n"&lt;BR /&gt;  }&lt;BR /&gt;  print XML "&lt;/WORDS&gt;\n&lt;/USER&gt;\n"'&lt;BR /&gt;}&lt;BR /&gt;close XML&lt;BR /&gt;if ($email_seen) { rename $xml, 'final.xml' }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy!&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 20 Oct 2009 20:18:34 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2009-10-20T20:18:34Z</dc:date>
    <item>
      <title>While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513474#M681348</link>
      <description>I have a file which has the following data - &lt;BR /&gt;&lt;BR /&gt;emailid1   word1   word2  word3&lt;BR /&gt;emailid2   word1   word3&lt;BR /&gt;&lt;BR /&gt;The spaces between the words are tab separated spaces.&lt;BR /&gt;&lt;BR /&gt;I want to echo each word on the line separately and at the same time consider the next line as a new line.&lt;BR /&gt;&lt;BR /&gt;Please help!</description>
      <pubDate>Tue, 13 Oct 2009 21:59:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513474#M681348</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-13T21:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513475#M681349</link>
      <description>cat file | while read a b c&lt;BR /&gt;do&lt;BR /&gt;echo $a $b $c&lt;BR /&gt;done</description>
      <pubDate>Tue, 13 Oct 2009 22:03:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513475#M681349</guid>
      <dc:creator>Michael Steele_2</dc:creator>
      <dc:date>2009-10-13T22:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513476#M681350</link>
      <description>Thanks Micheal!&lt;BR /&gt;&lt;BR /&gt;There is one more piece to it, the words can be more than 3 and the count cannot be predicted. I need a more dynamic way.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Oct 2009 22:06:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513476#M681350</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-13T22:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513477#M681351</link>
      <description>And dont want to print blank lines.</description>
      <pubDate>Tue, 13 Oct 2009 22:19:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513477#M681351</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-13T22:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513478#M681352</link>
      <description>&lt;!--!*#--&gt;Hi Allan:&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;    echo ${LINE}|tr -cs "[:alpha:]" "[\012*]"&lt;BR /&gt;done &amp;lt; file&lt;BR /&gt;&lt;BR /&gt;Spaces and/or tabs can separate the words in the file.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Oct 2009 22:22:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513478#M681352</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-13T22:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513479#M681353</link>
      <description>Hi (again) Allan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; And dont want to print blank lines.&lt;BR /&gt;&lt;BR /&gt;OK, so use:&lt;BR /&gt;&lt;BR /&gt;# cat ./lister&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;    [ -z "${LINE}" ] &amp;amp;&amp;amp; continue&lt;BR /&gt;    echo "${LINE}"|tr -cs "[:alpha:]" "[\012*]"&lt;BR /&gt;done &amp;lt; $1&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# ./lister file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 13 Oct 2009 22:27:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513479#M681353</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-13T22:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513480#M681354</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;In keeping with TIMTOWDI here's another way:&lt;BR /&gt;&lt;BR /&gt;# perl -nle 'next if m/^\s*$/;print join "\n",split' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 13 Oct 2009 22:36:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513480#M681354</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-13T22:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513481#M681355</link>
      <description>Thanks JRF!&lt;BR /&gt;&lt;BR /&gt;But this doesn't do what I want to achieve - &lt;BR /&gt;&lt;BR /&gt;Email-ids are of the pattern foo_bar@foobar.com and it is the first entry  on each line.I want to print that as is and add a certain html tags around it - &lt;BR /&gt;&lt;BR /&gt;&lt;USER name="foo_bar@foobar.com"&gt;&lt;BR /&gt;&lt;BR /&gt;and for the words like words1... I need &lt;WORD&gt;word1&lt;/WORD&gt; &lt;BR /&gt;&lt;WORD&gt;word2&lt;/WORD&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The final document should look like the following - &lt;BR /&gt;&lt;BR /&gt;&lt;USER name="foo_bar1@foobar.com"&gt;&lt;BR /&gt;&lt;WORDS&gt;&lt;BR /&gt; &lt;WORD&gt;word1&lt;/WORD&gt;&lt;BR /&gt; &lt;WORD&gt;words2&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;words3&lt;/WORD&gt;&lt;BR /&gt; &lt;/WORDS&gt;&lt;BR /&gt; &lt;/USER&gt;&lt;BR /&gt;&lt;USER name="foo_bar2@foobar.com"&gt;&lt;BR /&gt;&lt;WORDS&gt;&lt;BR /&gt; &lt;WORD&gt;word1&lt;/WORD&gt;&lt;BR /&gt; &lt;WORD&gt;words3&lt;/WORD&gt;&lt;BR /&gt; &lt;/WORDS&gt;&lt;BR /&gt; &lt;/USER&gt;&lt;/USER&gt;</description>
      <pubDate>Tue, 13 Oct 2009 22:46:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513481#M681355</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-13T22:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513482#M681356</link>
      <description>&lt;!--!*#--&gt;&amp;gt;I want to echo each word on the line separately&lt;BR /&gt;&lt;BR /&gt;for word in $(&amp;lt; file); do&lt;BR /&gt;   echo $word&lt;BR /&gt;done</description>
      <pubDate>Tue, 13 Oct 2009 23:00:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513482#M681356</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-10-13T23:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513483#M681357</link>
      <description>&lt;!--!*#--&gt;Hmm,&lt;BR /&gt;&lt;BR /&gt;Seems like your original problem statement can be satisfied with a simple:&lt;BR /&gt;&lt;BR /&gt;$ tr "\t" "\n" &amp;lt; tmp.txt&lt;BR /&gt;&lt;BR /&gt;look:&lt;BR /&gt;&lt;BR /&gt;$ cat tmp.txt&lt;BR /&gt;asergfewgfwegfew        aap     noot    mies&lt;BR /&gt;blah    more    data&lt;BR /&gt;$ od -c tmp.txt&lt;BR /&gt;0000000   a   s   e   r   g   f   e   w   g   f   w   e   g   f   e   w&lt;BR /&gt;0000020  \t   a   a   p  \t   n   o   o   t  \t   m   i   e   s  \n   b&lt;BR /&gt;0000040   l   a   h  \t   m   o   r   e  \t   d   a   t   a  \n&lt;BR /&gt;&lt;BR /&gt;$ tr "\t" "\n" &amp;lt; tmp.txt&lt;BR /&gt;asergfewgfwegfew&lt;BR /&gt;aap&lt;BR /&gt;noot&lt;BR /&gt;mies&lt;BR /&gt;blah&lt;BR /&gt;more&lt;BR /&gt;data&lt;BR /&gt;&lt;BR /&gt;But that's not really what you want apparently, and it looses the 'specialness' of the first word. Why not do it all in one perl one-line or program?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ perl -ne 'chomp; @words=split; $u=shift @words; print "&lt;USER name="\&amp;quot;$u\&amp;quot;"&gt;\n&lt;WORDS&gt;\n"; for (@words) {print "&lt;WORD&gt;$_&amp;lt;&lt;BR /&gt;/word&amp;gt;\n"}; print "&lt;/WORD&gt;\n&lt;/WORDS&gt;\n"' tmp.txt&lt;BR /&gt;&lt;USER name="asergfewgfwegfew"&gt;&lt;BR /&gt;&lt;WORDS&gt;&lt;BR /&gt;&lt;WORD&gt;aap&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;noot&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;mies&lt;/WORD&gt;&lt;BR /&gt;&lt;/WORDS&gt;&lt;BR /&gt;&lt;/USER&gt;&lt;BR /&gt;&lt;USER name="blah"&gt;&lt;BR /&gt;&lt;WORDS&gt;&lt;BR /&gt;&lt;WORD&gt;more&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;data&lt;/WORD&gt;&lt;BR /&gt;&lt;/WORDS&gt;&lt;BR /&gt;&lt;/USER&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy!&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/USER&gt;</description>
      <pubDate>Wed, 14 Oct 2009 00:42:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513483#M681357</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-10-14T00:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513484#M681358</link>
      <description>while read a b&lt;BR /&gt;do&lt;BR /&gt; set -- $b&lt;BR /&gt; echo 'email $a'&lt;BR /&gt; while [ $# != 0 ]&lt;BR /&gt; do&lt;BR /&gt;  echo word $1&lt;BR /&gt;  shift&lt;BR /&gt; done&lt;BR /&gt;done</description>
      <pubDate>Wed, 14 Oct 2009 07:44:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513484#M681358</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2009-10-14T07:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513485#M681359</link>
      <description>Hi Allan:&lt;BR /&gt;&lt;BR /&gt;Your original query was "I want to echo each word on the line".  Then, after a couple of offerings, you wrote, "Email-ids are of the pattern foo_bar@foobar.com and it is the first entry on each line.I want to print that as is and add a certain html tags around it -".&lt;BR /&gt;&lt;BR /&gt;This whole question, beginning with the subject was poorly framed.  The use of the word "word" in a language/scripting context is loaded with meaning alone.  You offered your input.  Offering a _sample_ of the output you wanted might have gone a long way to a more direct, faster solution.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 14 Oct 2009 10:40:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513485#M681359</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-14T10:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513486#M681360</link>
      <description>Thanks Hein,&lt;BR /&gt;&lt;BR /&gt;Works as expected, a couple of conditions where it can fail or I would like to handle is if there is a blank line or a line which is commented with a hash (#) then I would not like it to print anything and go on to the next entry.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.</description>
      <pubDate>Thu, 15 Oct 2009 17:58:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513486#M681360</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-15T17:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513487#M681361</link>
      <description>&lt;!--!*#--&gt;Hi Allan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; a couple of conditions where it can fail or I would like to handle is if there is a blank line or a line which is commented with a hash (#) then I would not like it to print anything and go on to the next entry.&lt;BR /&gt;&lt;BR /&gt;See if this meets your needs:&lt;BR /&gt;&lt;BR /&gt;# cat ./myfilter&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ( @F, $name, $word );&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    s/([^#]*).*/$1/;    #...snip off "#" and any trailing chars&lt;BR /&gt;    next if m/^\s*$/;   #...skip if only whitespace&lt;BR /&gt;    @F    = split;&lt;BR /&gt;    $name = shift @F;&lt;BR /&gt;    print qq(&lt;USER name="), $name, qq("&gt;\n&lt;WORDS&gt;\n);&lt;BR /&gt;    for $word (@F) {&lt;BR /&gt;        print qq(&lt;WORD&gt;), $word, qq(&lt;/WORD&gt;\n);&lt;BR /&gt;    }&lt;BR /&gt;    print qq(&lt;/WORDS&gt;\n&lt;/USER&gt;\n);&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;Now consider an input file like this:&lt;BR /&gt;&lt;BR /&gt;# cat -etv ./myinput&lt;BR /&gt;emailid1 word1^Iword2    word3$&lt;BR /&gt;    $&lt;BR /&gt;# this is a comment line$&lt;BR /&gt;^I$&lt;BR /&gt;emailid2   ^I worda wordb # and this piece is commentary too$&lt;BR /&gt;&lt;BR /&gt;...as you can see the ^I are tab characters and the $ characters mark the end-of-line.  Hence there are blank lines and comments signaled by hash ("#") marks at various points.&lt;BR /&gt;&lt;BR /&gt;Now:&lt;BR /&gt;&lt;BR /&gt;# ./myfilter ./myinput&lt;BR /&gt;&lt;USER name="emailid1"&gt;&lt;BR /&gt;&lt;WORDS&gt;&lt;BR /&gt;&lt;WORD&gt;word1&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;word2&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;word3&lt;/WORD&gt;&lt;BR /&gt;&lt;/WORDS&gt;&lt;BR /&gt;&lt;/USER&gt;&lt;BR /&gt;&lt;USER name="emailid2"&gt;&lt;BR /&gt;&lt;WORDS&gt;&lt;BR /&gt;&lt;WORD&gt;worda&lt;/WORD&gt;&lt;BR /&gt;&lt;WORD&gt;wordb&lt;/WORD&gt;&lt;BR /&gt;&lt;/WORDS&gt;&lt;BR /&gt;&lt;/USER&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 15 Oct 2009 19:09:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513487#M681361</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-15T19:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513488#M681362</link>
      <description>Thanks JRF/Hein.&lt;BR /&gt;&lt;BR /&gt;The only change I made was to - &lt;BR /&gt;&lt;BR /&gt;s/#.*//;&lt;BR /&gt;&lt;BR /&gt;instead of &lt;BR /&gt;&lt;BR /&gt;s/([^#]*).*/$1/&lt;BR /&gt;&lt;BR /&gt;=============&lt;BR /&gt;&lt;BR /&gt;Another set questions come to my mind since we are doing this in Perl.Originally I was working on shell script for this and the following variables were set related to saving the original file and saving the output in a intermediate XML file and moving that file over to be the destination file - &lt;BR /&gt;&lt;BR /&gt;Originally when I was planning this to do this in shell I was having something similar - &lt;BR /&gt;&lt;BR /&gt;===============================&lt;BR /&gt;&lt;BR /&gt;env=`hostname |awk -F"." '{print $2}'`&lt;BR /&gt;destination_xml="/a/g/m/admin.xml"&lt;BR /&gt;DATE=`date '+%Y%m%H%M'`&lt;BR /&gt;Intertim_xml="/a/g/m/admin.xml.interim.$DATE"&lt;BR /&gt;&lt;BR /&gt;if [ $# -lt 1 ]&lt;BR /&gt;then&lt;BR /&gt;        echo&lt;BR /&gt;        echo "Correct USAGE:"&lt;BR /&gt;        echo -e "\t\t$0 &lt;ARGUMENT file=""&gt;\n"  &lt;BR /&gt;        exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;# Save the target XML file before renewing it&lt;BR /&gt;cp ${destination_xml} ${destination_xml}.${DATE}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while read Line {&lt;BR /&gt;....&lt;BR /&gt;}  1&amp;gt;&amp;gt; $Interim_xml&lt;BR /&gt;&lt;BR /&gt;mv ${Interim_xml} ${destination_xml}&lt;BR /&gt;&lt;BR /&gt;====================&lt;BR /&gt;&lt;BR /&gt;How do I port this in Perl?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.&lt;/ARGUMENT&gt;</description>
      <pubDate>Thu, 15 Oct 2009 22:22:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513488#M681362</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-15T22:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513489#M681363</link>
      <description>Hi (again) Allan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Another set questions come to my mind since we are doing this in Perl.  Originally I was working on shell script for this and the following variables were set related to saving the original file and saving the output in a intermediate XML file and moving that file over to be the destination file - &lt;BR /&gt;&lt;BR /&gt;This is painless in Perl (of course!).  Simply add the '-i' switch to enable inplace editting.&lt;BR /&gt;&lt;BR /&gt;Using my last script, change:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;to:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -i.old&lt;BR /&gt;&lt;BR /&gt;This specifies an "in-place" edit of the input file (passed as the argument to the script).  A backup copy of the original file is made automatically, nameing it with its original name suffixed with ".old" [or whatever you want].&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Oct 2009 22:34:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513489#M681363</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-15T22:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513490#M681364</link>
      <description>as always Thanks JRF!!! :)&lt;BR /&gt;&lt;BR /&gt;That takes care of the input file.&lt;BR /&gt;&lt;BR /&gt;I want that to happen to the interim file and as well as target xml file. (as described in the "cp" and "mv" commands above).&lt;BR /&gt;&lt;BR /&gt;How do I achieve that?&lt;BR /&gt;&lt;BR /&gt;How do I specify the following variables in the Perl script - &lt;BR /&gt;&lt;BR /&gt;env=`hostname |awk -F"." '{print $2}'` # so that the script run in any environment&lt;BR /&gt;destination_xml="/a/g/m/admin.xml" #target xml&lt;BR /&gt;DATE=`date '+%Y%m%H%M'`&lt;BR /&gt;Intertim_xml="/a/g/m/admin.xml.interim.$DATE"&lt;BR /&gt;&lt;BR /&gt;Also I would like to handle a failure condition wherein if the input file is empty then it should use the previously saved input file...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Oct 2009 22:56:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513490#M681364</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-15T22:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513491#M681365</link>
      <description>&amp;gt;&amp;gt; I want that to happen to the interim file and as well as target xml file. (as described in the "cp" and "mv" commands above).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You want to try to use the perl command "rename"&lt;BR /&gt;Ir you can call: system(qq(cp.... ))&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&amp;gt;&amp;gt; How do I specify the following variables in the Perl script - &lt;BR /&gt;env=`hostname |awk -F"." '{print $2}'` # so that the script run in any environment&lt;BR /&gt;&lt;BR /&gt;There is a perl module for that:&lt;BR /&gt;Try this: perl -e "use Sys::Hostname; print hostname"&lt;BR /&gt;&lt;BR /&gt;So just use the function 'hostname' in the program, after declaring it from "Sys" &lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; destination_xml="/a/g/m/admin.xml" #target xml&lt;BR /&gt;&lt;BR /&gt;Just a piece of string.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; DATE=`date '+%Y%m%H%M'`&lt;BR /&gt;&lt;BR /&gt;There is a locasltim function for that:&lt;BR /&gt;&lt;BR /&gt;perl -e '($sec,$min,$hour,$mday,$mon,$year)=localtime; printf qq(%d%02d%02d%02d\n),$year+1900,$mon+1,$day,$hour,$min'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Also I would like to handle a failure condition wherein if the input file is empty then it should use the previously saved input file...&lt;BR /&gt;&lt;BR /&gt;You could protect that with some defensive shell code before calling perl.&lt;BR /&gt;Of, in the perl script you couls explicitly create the output only if data exists.&lt;BR /&gt;&lt;BR /&gt;Tou can pre-test with the '-s ' function,&lt;BR /&gt;or you can loop and only open on first data"&lt;BR /&gt;&lt;BR /&gt;While (&amp;lt;&amp;gt;) {&lt;BR /&gt;   open $out,"&amp;gt;x.x" unless $out&lt;BR /&gt;   :&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Oct 2009 05:30:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513491#M681365</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-10-16T05:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513492#M681366</link>
      <description>Thanks Hein,&lt;BR /&gt;&lt;BR /&gt;I did a small mistake, in the destination xml I want to use the env variable so that it can run on different environments and be environment independent.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;env=`hostname |awk -F"." '{print $2}'`&lt;BR /&gt;destination_xml="/a/g/$env/admin.xml"&lt;BR /&gt;&lt;BR /&gt;How do I do that in Perl script.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan</description>
      <pubDate>Fri, 16 Oct 2009 17:44:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513492#M681366</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-16T17:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop Question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513493#M681367</link>
      <description>Hi Allan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; env=`hostname |awk -F"." '{print $2}'`&lt;BR /&gt;&amp;gt; destination_xml="/a/g/$env/admin.xml"&lt;BR /&gt;&amp;gt; How do I do that in Perl script.&lt;BR /&gt;&lt;BR /&gt;As Hein said, there is a Perl module to fetch the hostname:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use Sys::Hostname;&lt;BR /&gt;my $env=hostname;&lt;BR /&gt;my $destination_xml = "/a/g/$env/admin.xml";&lt;BR /&gt;print "I point to '$destination_xml'\n";&lt;BR /&gt;&lt;BR /&gt;That said, I am a bit confused when you said, "Originally I was working on shell script for this and the following variables were set related to saving the original file and saving the output in a intermediate XML file and moving that file over to be the destination file".  &lt;BR /&gt;&lt;BR /&gt;Specifically, what's wrong with the inplace edit I showed you?  After all, Perl does what you would do via an intermediate file with a Perl-slight-of-hand.  If the updated file isn't what you want, the use of the ".old" [or whatever you would choose] allows you to restore the original file by 'rename'ing it as Hein noted.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Oct 2009 18:01:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/while-loop-question/m-p/4513493#M681367</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-16T18:01:33Z</dc:date>
    </item>
  </channel>
</rss>

