<?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 for copying and renaming files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893695#M103553</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I think that previous scripts don't care about the -new-new-new... problem:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;DIR="mydir"&lt;BR /&gt;STRING="-new"&lt;BR /&gt;for VAR in $(ls $DIR 2&amp;gt;&amp;amp;- | grep -v "$NEW"$)&lt;BR /&gt;do&lt;BR /&gt;  cp $VAR $VAR$STRING&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
    <pubDate>Fri, 31 Jan 2003 08:16:18 GMT</pubDate>
    <dc:creator>Jean-Louis Phelix</dc:creator>
    <dc:date>2003-01-31T08:16:18Z</dc:date>
    <item>
      <title>script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893691#M103549</link>
      <description>I have hit a brick wall with a script.&lt;BR /&gt;Can anyone plese help.&lt;BR /&gt;&lt;BR /&gt;I need to copy all the files from a directory to files within the same directory with a different name. For example.&lt;BR /&gt;filename1  ---&amp;gt; filename1-new&lt;BR /&gt;filename2  ---&amp;gt; filename2-new&lt;BR /&gt;filename3  ---&amp;gt; filename3-new&lt;BR /&gt;This will be done daily so I don't want to end up with additional copies as the script is run each day, like filename1-new and filename1-new-new and filename1-new-new-new, I want the new file to be overwritten.&lt;BR /&gt; &lt;BR /&gt;Then I want to sort through these new files for a string of text and replace it.&lt;BR /&gt; &lt;BR /&gt;Any help or advise would be greatly appreciated.</description>
      <pubDate>Fri, 31 Jan 2003 06:44:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893691#M103549</guid>
      <dc:creator>Reach Managed Service</dc:creator>
      <dc:date>2003-01-31T06:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893692#M103550</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Renaming the files is simple.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;DIR=/your_dir&lt;BR /&gt;&lt;BR /&gt;for FILE in ls $DIR&lt;BR /&gt;do&lt;BR /&gt;cp ${DIR}/${FILE} ${DIR}/${FILE-new}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Now what kind of text is this?. Is this same everyday or does it change?.&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Fri, 31 Jan 2003 06:49:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893692#M103550</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2003-01-31T06:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893693#M103551</link>
      <description>I will re-write the script with a correction and to replace string.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;DIR=/your_dir&lt;BR /&gt;STRING="this is a string"&lt;BR /&gt;REPLACE="replace it"&lt;BR /&gt;&lt;BR /&gt;for FILE in $(ls ${DIR})&lt;BR /&gt;do&lt;BR /&gt;sed 's/'"$STRING"'/'"$REPLACE"'/g' ${DIR}/${FILE} &amp;gt; ${DIR}/${FILE}-new&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 31 Jan 2003 07:05:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893693#M103551</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2003-01-31T07:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893694#M103552</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;#cd /&lt;DIR&gt;&lt;BR /&gt;#ls &amp;gt; file&lt;BR /&gt;&lt;BR /&gt;#for i in `cat file`&lt;BR /&gt;do&lt;BR /&gt;mv $i $i-new&lt;BR /&gt;done&lt;/DIR&gt;</description>
      <pubDate>Fri, 31 Jan 2003 07:52:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893694#M103552</guid>
      <dc:creator>Ravi_8</dc:creator>
      <dc:date>2003-01-31T07:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893695#M103553</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I think that previous scripts don't care about the -new-new-new... problem:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;DIR="mydir"&lt;BR /&gt;STRING="-new"&lt;BR /&gt;for VAR in $(ls $DIR 2&amp;gt;&amp;amp;- | grep -v "$NEW"$)&lt;BR /&gt;do&lt;BR /&gt;  cp $VAR $VAR$STRING&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Fri, 31 Jan 2003 08:16:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893695#M103553</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-01-31T08:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893696#M103554</link>
      <description>Hi,&lt;BR /&gt;it is not practical to use the hyphen/slash character as extension for filenames, particularly not if you have to specify it as parameter for a command, e.g. grep: the shell mistakes it for a command option. Underscore is better.&lt;BR /&gt; You could try that as a variation on the script made by Jean Phelix, e.g.:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh &lt;BR /&gt;DIR="mydir"&lt;BR /&gt;STRING="_new"&lt;BR /&gt;cd $DIR&lt;BR /&gt;for VAR in $(ls $DIR 2&amp;gt;&amp;amp;- | grep -v "$STRING"$)&lt;BR /&gt;do&lt;BR /&gt;cp  $VAR $VAR$STRING&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Fri, 31 Jan 2003 10:01:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893696#M103554</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-01-31T10:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893697#M103555</link>
      <description>Thanks John ... I didn't really test the script ! But if you want to keep "-new" string then you can also simply add "--" after grep options :&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh &lt;BR /&gt;DIR="mydir" &lt;BR /&gt;STRING="-new" &lt;BR /&gt;for VAR in $(ls $DIR 2&amp;gt;&amp;amp;- | grep -v -- "$NEW"$) &lt;BR /&gt;do &lt;BR /&gt;  cp $VAR $VAR$STRING &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Fri, 31 Jan 2003 10:34:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893697#M103555</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-01-31T10:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893698#M103556</link>
      <description>Hi Jean-Phelix,&lt;BR /&gt;you are of course right.  However, the reason why I added your script in full was that I suggested two other changes to it. &lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Fri, 31 Jan 2003 11:06:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893698#M103556</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-01-31T11:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893699#M103557</link>
      <description>Ooooops ... Last mistake in the pattern ! The ending $ should be inside.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;DIR="mydir"&lt;BR /&gt;STRING="-new"&lt;BR /&gt;for VAR in $(ls $DIR 2&amp;gt;&amp;amp;- | grep -v -- "$NEW$")&lt;BR /&gt;do&lt;BR /&gt;  cp $VAR $VAR$STRING&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Fri, 31 Jan 2003 11:13:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893699#M103557</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-01-31T11:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893700#M103558</link>
      <description>Hi again,&lt;BR /&gt;I was actually more thinking about the "$NEW" variable and about to be in the correct location...&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Fri, 31 Jan 2003 11:26:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893700#M103558</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-01-31T11:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893701#M103559</link>
      <description>Why can't we write rm *-new as the first statement of the script and then proceed to copy the existing files to _new files?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;VJ</description>
      <pubDate>Mon, 03 Feb 2003 07:27:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893701#M103559</guid>
      <dc:creator>vasundhara</dc:creator>
      <dc:date>2003-02-03T07:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893702#M103560</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;you like living dangerously, all of you, don't you?&lt;BR /&gt;&lt;BR /&gt;Nobody test for the extistance of the "new" filename :-(&lt;BR /&gt;&lt;BR /&gt;So you may cause a lot of loss!&lt;BR /&gt;&lt;BR /&gt;I would try to be more carefull (but then, it's not my data):&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;if [ -d "$1" ]&lt;BR /&gt;then echo "no DIR to start from" 1&amp;gt;&amp;amp;2&lt;BR /&gt;exit 1&lt;BR /&gt;fi&lt;BR /&gt;cd "$1"&lt;BR /&gt;ls -1 | # could be MANY files!&lt;BR /&gt;while read oldname&lt;BR /&gt;do new="${oldname}-new"&lt;BR /&gt;if ls "$new" &amp;gt; /dev/null&lt;BR /&gt;# could already exist as:&lt;BR /&gt;# file/directory/blockdev/chardev/pipe/symlink/socket&lt;BR /&gt;then echo "${oldname} cannot be renamed: ${new} already exists!" 1&amp;gt;&amp;amp;2&lt;BR /&gt;exit 2&lt;BR /&gt;else if mv "$oldname" "$new"&lt;BR /&gt;then : #ok!&lt;BR /&gt;else echo "mv $oldname $new did NOT work!" 1&amp;gt;&amp;amp;2&lt;BR /&gt;exit 3&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;# end&lt;BR /&gt;&lt;BR /&gt;this may still have typos in , but can you see my point?&lt;BR /&gt;Be careful, check for errors!&lt;BR /&gt;&lt;BR /&gt;FWIW,&lt;BR /&gt;Wodisch</description>
      <pubDate>Tue, 04 Feb 2003 00:42:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893702#M103560</guid>
      <dc:creator>Wodisch</dc:creator>
      <dc:date>2003-02-04T00:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: script for copying and renaming files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893703#M103561</link>
      <description>Hi Wodisch,&lt;BR /&gt;I can of course only speak for myself, as I single-handledly stole Jean-Louis' script. The simple answer is that my interpretation of the demands for the script is  different from yours. &lt;BR /&gt;It is for instance required that the files be copied, not moved. It is also said that:&lt;BR /&gt;&lt;BR /&gt;I want the new file to be overwritten.&lt;BR /&gt;&lt;BR /&gt;Therefore, I did not think  that the script should avoid overwriting existing files that have the "copied  extension". &lt;BR /&gt;I imagined a scenario where the files in the directory that did not have the "copied extension" were daily overwritten/updated by some application, and then - at a certain point in time - the files should be copied by the script, in order to create  a "daily copy of things as they were at that particular point in time". I thought that made good sense, as there afterwards should be made some search and replacement in the "daily copied" files. &lt;BR /&gt;But it is only my  interpretation and I could very well be wrong - unfortunately, a situation that would not be totally new to me.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.   &lt;BR /&gt;</description>
      <pubDate>Tue, 04 Feb 2003 09:32:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-copying-and-renaming-files/m-p/2893703#M103561</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-02-04T09:32:27Z</dc:date>
    </item>
  </channel>
</rss>

