<?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: Removing files within a  script. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807759#M939775</link>
    <description>If I understand your question then it's rather simple and you don't need a -exec argument.&lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;find /var/adm/sa -name 'sa[0-3]*' -mtime +10 | while read FNAME&lt;BR /&gt;do&lt;BR /&gt;  echo "Filename: ${FNAME}"&lt;BR /&gt;  # if you want to read the file contents put a 2nd loop here&lt;BR /&gt;  cat ${FNAME} | while read X&lt;BR /&gt;   do&lt;BR /&gt;     echo "${X}"&lt;BR /&gt;   done&lt;BR /&gt;  rm ${FNAME}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Note that I also replaced your double quotes with single quotes.&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 17 Sep 2002 14:02:00 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2002-09-17T14:02:00Z</dc:date>
    <item>
      <title>Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807758#M939774</link>
      <description>Hello all.&lt;BR /&gt;&lt;BR /&gt;I am trying to figure out within a particular script that I am writing how to remove files that are written to 2 different log files. The files are found using the following find statements:&lt;BR /&gt;&lt;BR /&gt;find / -type f -name core -exec ls &amp;gt; $BASEDIR/$CORELOG {} \;&lt;BR /&gt;&lt;BR /&gt;find /var/adm/sa -name "sa[0-3]*" -mtime +10 -exec ls &amp;gt; $BASEDIR/$SARLOG {} \;&lt;BR /&gt;&lt;BR /&gt;As you can see there are 2 log files here, $CORELOG and $SARLOG. So what I would like to do is write a WHILE READ statement after each of the find commands that takes each logfile and reads it's contents, then removes each of the files listed. &lt;BR /&gt;&lt;BR /&gt;BTW: I know that I can accomplish this by simply adding the following to the end of each find command:  -exec rm -f {} \;&lt;BR /&gt;&lt;BR /&gt;But I am trying to get an idea how the WHILE READ commands would work with this.&lt;BR /&gt;&lt;BR /&gt;Thank you all.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Sep 2002 13:51:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807758#M939774</guid>
      <dc:creator>fg_1</dc:creator>
      <dc:date>2002-09-17T13:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807759#M939775</link>
      <description>If I understand your question then it's rather simple and you don't need a -exec argument.&lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;find /var/adm/sa -name 'sa[0-3]*' -mtime +10 | while read FNAME&lt;BR /&gt;do&lt;BR /&gt;  echo "Filename: ${FNAME}"&lt;BR /&gt;  # if you want to read the file contents put a 2nd loop here&lt;BR /&gt;  cat ${FNAME} | while read X&lt;BR /&gt;   do&lt;BR /&gt;     echo "${X}"&lt;BR /&gt;   done&lt;BR /&gt;  rm ${FNAME}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Note that I also replaced your double quotes with single quotes.&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Sep 2002 14:02:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807759#M939775</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-09-17T14:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807760#M939776</link>
      <description>Hi Frank,&lt;BR /&gt;&lt;BR /&gt;I would try something like this:&lt;BR /&gt;&lt;BR /&gt;find / -type f -name core | tee $BASEDIR/$CORELOG | xargs rm&lt;BR /&gt;&lt;BR /&gt;If you simply want to remove the files contained in the logfiles after the find command:&lt;BR /&gt;&lt;BR /&gt;rm `cat $BASEDIR/$CORELOG`&lt;BR /&gt;&lt;BR /&gt;or if you want to use while read:&lt;BR /&gt;&lt;BR /&gt;cat $BASEDIR/$CORELOG | while read file ; do&lt;BR /&gt;rm $file&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Tue, 17 Sep 2002 14:02:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807760#M939776</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2002-09-17T14:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807761#M939777</link>
      <description>Hi Frank:&lt;BR /&gt;&lt;BR /&gt;Instead of this:&lt;BR /&gt;&lt;BR /&gt;cat $BASEDIR/$CORELOG | while read file&lt;BR /&gt;do &lt;BR /&gt;rm $file &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;...use:&lt;BR /&gt;&lt;BR /&gt;while read file&lt;BR /&gt;do&lt;BR /&gt;rm $file&lt;BR /&gt;done &amp;lt; $BASEDIR/$CORELOG&lt;BR /&gt;&lt;BR /&gt;...you eliminate the 'cat' process...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 17 Sep 2002 14:21:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807761#M939777</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-09-17T14:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807762#M939778</link>
      <description>Hi&lt;BR /&gt;Sure there is many ways to do this.&lt;BR /&gt;&lt;BR /&gt;Below is a example how to redirect input inside a script.&lt;BR /&gt;&lt;BR /&gt;# create a list of files&lt;BR /&gt;&lt;BR /&gt;find ......  &amp;gt;$BASEDIR/$SARLOG &lt;BR /&gt;# Redirect input from the file.&lt;BR /&gt;exec &amp;lt;$BASEDIR/$SARLOG &lt;BR /&gt;while read a&lt;BR /&gt;do&lt;BR /&gt;# DO SOMETHING&lt;BR /&gt;done&lt;BR /&gt;# Redirect input from stdin.&lt;BR /&gt;exec &amp;lt;&amp;amp;1&lt;BR /&gt;rm $BASEDIR/$SARLOG &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Sep 2002 14:39:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807762#M939778</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2002-09-17T14:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807763#M939779</link>
      <description>`while read` may actually be slower. Why not group the finds into a single pipe to xargs?&lt;BR /&gt;&lt;BR /&gt;( find / -type f -name core; find /var/adm/sa -name 'sa[0-3]*' -mtime +10; ) | xargs rm -f &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Sep 2002 14:48:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807763#M939779</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2002-09-17T14:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing files within a  script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807764#M939780</link>
      <description>All of the answers here were right on in their own ways. I ended up using JRF's idea's and it works great.&lt;BR /&gt;&lt;BR /&gt;Thanks to all of you, this is truly the greatest users group/forum I have ever been a part of.&lt;BR /&gt;&lt;BR /&gt;Fg.</description>
      <pubDate>Tue, 17 Sep 2002 17:13:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/removing-files-within-a-script/m-p/2807764#M939780</guid>
      <dc:creator>fg_1</dc:creator>
      <dc:date>2002-09-17T17:13:52Z</dc:date>
    </item>
  </channel>
</rss>

