<?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: script challenge - file moving in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009836#M911271</link>
    <description>I guess we have to "assume" that the second field is always the job number. &lt;BR /&gt;&lt;BR /&gt;This may be lengthy, but I like to see what's going on and keep it simple for the next person.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;ARCH_DIR=/prod/temp/ascribe_archives&lt;BR /&gt;MV_BASE=/prod/job1&lt;BR /&gt;LOG=/tmp/file_mover.log&lt;BR /&gt;if [ -f $LOG ] ; then&lt;BR /&gt;  rm -f $LOG&lt;BR /&gt;fi&lt;BR /&gt;touch $LOG&lt;BR /&gt;cd $ARCH&lt;BR /&gt;for FILE in `ls` ; do&lt;BR /&gt;NEWDIR=`echo $FILE|awk -F_ '{print $2}'`&lt;BR /&gt;if [ -d ${MV_BASE}/$NEWDIR ] ; then&lt;BR /&gt;echo "Moving ${ARCH_DIR}/${FILE} to ${MV_BASE}/${NEWDIR}" &amp;gt;&amp;gt;$LOG&lt;BR /&gt;mv $FILE ${MV_BASE}/$NEWDIR&lt;BR /&gt;else&lt;BR /&gt;echo "No such Directory ${MV_BASE}/${NEWDIR}" &amp;gt;&amp;gt;$LOG&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Shannon</description>
    <pubDate>Fri, 27 Jun 2003 13:36:47 GMT</pubDate>
    <dc:creator>Shannon Petry</dc:creator>
    <dc:date>2003-06-27T13:36:47Z</dc:date>
    <item>
      <title>script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009826#M911261</link>
      <description>I need to create a script that will move files based on information in the file name.  I have a temporary directory in which a bunch of .zip files reside.  Each zip file has a job number in the file name, and I need to be able to move them to the appropriate production directory based on the job number information in the file name.  For example:&lt;BR /&gt;# ll /prod/temp/ascribe_archives&lt;BR /&gt;total 17124&lt;BR /&gt;-rw-rw-rw-   1 jmickens   users       351465 Jun 26 14:31 20030115_j341281_Morgan_Stanley_Retail_RDD_Q1_2003.zip&lt;BR /&gt;-rw-rw-rw-   1 jmickens   users       137011 Jun 26 14:31 20030120_j341271_Morgan_Stanley_Heavy_Up_RDD_Q1_2003.zip&lt;BR /&gt;&lt;BR /&gt;The first file needs to be moved to /prod/job1/j341281, and the second needs to be moved to /prod/job1/j341271.&lt;BR /&gt;&lt;BR /&gt;The job number will always appear between the first two underscores, but may not always be the same length (some might have 5 digits, others 6).  I also need to leave the file where it is if the production directory that it goes with doesn't already exist.  The reason I need to automate this is that these are files that are downloaded from a supplier ftp site every week. &lt;BR /&gt;&lt;BR /&gt;I'm not a high-level script programmer.  Any suggestions would be greatly appreciated.</description>
      <pubDate>Fri, 27 Jun 2003 12:01:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009826#M911261</guid>
      <dc:creator>Jim Mickens</dc:creator>
      <dc:date>2003-06-27T12:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009827#M911262</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;cd /prod/temp/ascribe_archives&lt;BR /&gt;ls | grep j341281 | while read LINE&lt;BR /&gt;do &lt;BR /&gt;mv $LINE /prod/job1/j341281/&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cd /prod/temp/ascribe_archives&lt;BR /&gt;ls | grep j341271 | while read LINE&lt;BR /&gt;do &lt;BR /&gt;mv $LINE /prod/job1/j341271/&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Robert-Jan.&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jun 2003 12:06:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009827#M911262</guid>
      <dc:creator>Robert-Jan Goossens</dc:creator>
      <dc:date>2003-06-27T12:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009828#M911263</link>
      <description>for i in $(ls /prod/temp/ascribe_archives)&lt;BR /&gt;do&lt;BR /&gt;echo ARCH_DIR=`echo $i |sed 's/_/ /g' |awk '{print $2}'`&lt;BR /&gt;&lt;BR /&gt;if [[ ! -d /prod/job1/$ARCH_DIR ]]&lt;BR /&gt;then&lt;BR /&gt;   # Directory does not exist&lt;BR /&gt;   mkdir /prod/job1/$ARCH_DIR &lt;BR /&gt;   if (( $? &amp;lt; 1 ))&lt;BR /&gt;   then&lt;BR /&gt;      print "error"&lt;BR /&gt;   fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;cp $i /prod/job1/$ARCH_DIR &lt;BR /&gt;if [[ -f /prod/job1/$ARCH_DIR/$i ]]&lt;BR /&gt;then&lt;BR /&gt;    rm $i&lt;BR /&gt;else&lt;BR /&gt;    echo "could not move file $i"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This script ensures that the file is not deleted until it is a valid entry in the sub-directory.&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jun 2003 12:08:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009828#M911263</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2003-06-27T12:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009829#M911264</link>
      <description>Sorry, &lt;BR /&gt;&lt;BR /&gt;if (( $? &amp;lt; 1 )) &lt;BR /&gt;&lt;BR /&gt;should read&lt;BR /&gt;&lt;BR /&gt;if (( $? &amp;gt; 0 )) &lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jun 2003 12:10:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009829#M911264</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2003-06-27T12:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009830#M911265</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;cd /prod/temp/ascribe_archives &lt;BR /&gt;for FILE in $(ls 2&amp;gt;&amp;amp;-)&lt;BR /&gt;do&lt;BR /&gt;  JOB=$(echo $FILE | sed 's;^[^_]*_\([^_]*\)_.*$;\1;')&lt;BR /&gt;  [ -d "/prod/job1/$JOB ] || continue&lt;BR /&gt;  mv $FILE /prod/job1/$JOB&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Fri, 27 Jun 2003 12:10:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009830#M911265</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-06-27T12:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009831#M911266</link>
      <description>I would do something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;LIST=$( find /prod/temp/ascribe_archives -type f -print)&lt;BR /&gt;&lt;BR /&gt;for i in $LIST&lt;BR /&gt;do&lt;BR /&gt;# this is the dest directory&lt;BR /&gt;DEST_DIR=$( echo $i| awk -F_ '{print $2}' )&lt;BR /&gt;FULL_DIR=/prod/job1/$DEST_DIR&lt;BR /&gt;if [-d $FULL_DIR] &lt;BR /&gt;then &lt;BR /&gt;mv $i $FULL_DIR&lt;BR /&gt;else&lt;BR /&gt;echo $FULL_DIR not found, skipping file $i&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt; Massimo&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jun 2003 12:12:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009831#M911266</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-27T12:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009832#M911267</link>
      <description>Hi Jim:&lt;BR /&gt;&lt;BR /&gt;This will get you started:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;cd /tmp&lt;BR /&gt;ls -l 2003*|awk '{print $NF}'|while read F&lt;BR /&gt;do&lt;BR /&gt;  FF=`echo ${F}|awk -F"_" '{print $2}'`&lt;BR /&gt;  echo cp ${F} /prod/job/${FF}&lt;BR /&gt;done&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;I have assumed that your source files reside in the '/tmp' directory in the above example.  I have also assumed that they are named starting with the string "2003".  Drop the 'echo' in front of the 'cp' and files will actually be copied.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 27 Jun 2003 12:17:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009832#M911267</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2003-06-27T12:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009833#M911268</link>
      <description>Hi,&lt;BR /&gt;a little futher check to add, at everyone's reply (mine inclusive):&lt;BR /&gt;&lt;BR /&gt;let's suppone that $i is source &lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;cp $i $DEST_DIR/$i&lt;BR /&gt;diff $i $DEST_DIR 1&amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&amp;amp; rm $i&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;so you are sure that the file copied was not being edited :)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cheers,&lt;BR /&gt;   Massimo&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jun 2003 12:22:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009833#M911268</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-27T12:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009834#M911269</link>
      <description>Hi,&lt;BR /&gt;a little futher check to add, at everyone's reply (mine inclusive):&lt;BR /&gt;&lt;BR /&gt;let's suppone that $i is source &lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;cp $i $DEST_DIR/$i&lt;BR /&gt;diff $i $DEST_DIR/$i 1&amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&amp;amp; rm $i&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;so you are sure that the file copied was not being edited :)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cheers,&lt;BR /&gt;   Massimo&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jun 2003 12:23:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009834#M911269</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-27T12:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009835#M911270</link>
      <description>So many suggestions, and so quickly!  Now I need time to absorb and test.  Thanks everyone.  I'll let you know how it turns out.</description>
      <pubDate>Fri, 27 Jun 2003 13:22:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009835#M911270</guid>
      <dc:creator>Jim Mickens</dc:creator>
      <dc:date>2003-06-27T13:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009836#M911271</link>
      <description>I guess we have to "assume" that the second field is always the job number. &lt;BR /&gt;&lt;BR /&gt;This may be lengthy, but I like to see what's going on and keep it simple for the next person.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;ARCH_DIR=/prod/temp/ascribe_archives&lt;BR /&gt;MV_BASE=/prod/job1&lt;BR /&gt;LOG=/tmp/file_mover.log&lt;BR /&gt;if [ -f $LOG ] ; then&lt;BR /&gt;  rm -f $LOG&lt;BR /&gt;fi&lt;BR /&gt;touch $LOG&lt;BR /&gt;cd $ARCH&lt;BR /&gt;for FILE in `ls` ; do&lt;BR /&gt;NEWDIR=`echo $FILE|awk -F_ '{print $2}'`&lt;BR /&gt;if [ -d ${MV_BASE}/$NEWDIR ] ; then&lt;BR /&gt;echo "Moving ${ARCH_DIR}/${FILE} to ${MV_BASE}/${NEWDIR}" &amp;gt;&amp;gt;$LOG&lt;BR /&gt;mv $FILE ${MV_BASE}/$NEWDIR&lt;BR /&gt;else&lt;BR /&gt;echo "No such Directory ${MV_BASE}/${NEWDIR}" &amp;gt;&amp;gt;$LOG&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Shannon</description>
      <pubDate>Fri, 27 Jun 2003 13:36:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009836#M911271</guid>
      <dc:creator>Shannon Petry</dc:creator>
      <dc:date>2003-06-27T13:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: script challenge - file moving</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009837#M911272</link>
      <description>Got it working.  Thanks to everyone for thier suggestions. I couldn't have done it without you! I wound up using a modified version of the script Ian posted.  I have attached it for anyone interested.  Works like a charm.</description>
      <pubDate>Fri, 27 Jun 2003 19:23:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenge-file-moving/m-p/3009837#M911272</guid>
      <dc:creator>Jim Mickens</dc:creator>
      <dc:date>2003-06-27T19:23:12Z</dc:date>
    </item>
  </channel>
</rss>

