<?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: simplest way to strip a character from a filename in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961734#M101178</link>
    <description>for file in *&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; mv $file `echo $file | perl -ple 's/\://g'`&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;==&lt;BR /&gt;&lt;BR /&gt;Simply as,&lt;BR /&gt;&lt;BR /&gt;for file in `ls`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  mv ${file} $(echo ${file} | perl -pe 's/://g')&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Muthu</description>
    <pubDate>Tue, 21 Feb 2006 22:50:38 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2006-02-21T22:50:38Z</dc:date>
    <item>
      <title>simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961728#M101172</link>
      <description>I have a gazzilion tiny files each with multiple ':' in the file name.  I need to strip these out.&lt;BR /&gt;&lt;BR /&gt;A sample file name is: x_0041257026_102110535974_2006-01-26T20:33:31.272Z.xml.28_00_05.Z&lt;BR /&gt;&lt;BR /&gt;I wrote a clumbsy perl script to do it which is working but it soooo slooooow.&lt;BR /&gt;&lt;BR /&gt;Is there a mean, easy and efficient way to do this?&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2006 19:52:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961728#M101172</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2006-02-21T19:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961729#M101173</link>
      <description>Hi David:&lt;BR /&gt;&lt;BR /&gt;# perl -ple 's/\.//g;s/Z$/\.Z/'&lt;BR /&gt;&lt;BR /&gt;As for example:&lt;BR /&gt;&lt;BR /&gt;# echo "12.3\nabc_def.xyz\ndavid.Z"|perl -ple 's/\.//g;s/Z$/\.Z/'&lt;BR /&gt;&lt;BR /&gt;(or):&lt;BR /&gt;&lt;BR /&gt;# perl -ple 's/\.//g;s/Z$/\.Z/' fileofnames&lt;BR /&gt;&lt;BR /&gt;This (crudely) preserves the ".Z" extension if present.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2006 20:18:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961729#M101173</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-02-21T20:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961730#M101174</link>
      <description>Don't have a solution for the renaming, but as far as generation of the files - did you fix that so that it doesn't do the :&lt;BR /&gt;&lt;BR /&gt;Looks like a time stamp...&lt;BR /&gt;&lt;BR /&gt;Could do something like:&lt;BR /&gt;&lt;BR /&gt;date '+%FT%H%M%S'&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Tue, 21 Feb 2006 20:19:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961730#M101174</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2006-02-21T20:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961731#M101175</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Try this awk construct...&lt;BR /&gt;&lt;BR /&gt;# ls -1 &lt;DIR containing="" the="" files=""&gt; | awk '{gsub(":",""); print $0}'&lt;BR /&gt;&lt;BR /&gt;cheers!&lt;/DIR&gt;</description>
      <pubDate>Tue, 21 Feb 2006 20:23:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961731#M101175</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-02-21T20:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961732#M101176</link>
      <description>I am not sure that this is particularly efficient because it invokes perl for each mv but this is currently doing what I want:&lt;BR /&gt;&lt;BR /&gt;for file in *&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; mv $file `echo $file | perl -ple 's/\://g'`&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;Note that the char I wished to replace was a : and not a .&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2006 21:36:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961732#M101176</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2006-02-21T21:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961733#M101177</link>
      <description>Something like this should work leveraging the tr command:&lt;BR /&gt;&lt;BR /&gt;ls | while read FNAME&lt;BR /&gt;  do&lt;BR /&gt;     FNAME2=$(echo "${FNAME}" | tr -d ":")&lt;BR /&gt;     if [[ "${FNAME}" != "${FNAME2}" &amp;amp;&amp;amp; -n "${FNAME2}" ]]&lt;BR /&gt;       then&lt;BR /&gt;         if [[ -r "${FNAME2}" ]]&lt;BR /&gt;           then&lt;BR /&gt;             echo "${FNAME2} exists; can't mv" &amp;gt;&amp;amp;2&lt;BR /&gt;           else&lt;BR /&gt;             mv "${FNAME}" "${FNAME2}"&lt;BR /&gt;           fi&lt;BR /&gt;       fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The idea is that we use tr -d to strip the ':'s from the filename. Next we check to see if the filenames are then diffirent and also that the filename still has a non-zero length. Next we make sure that the new filename does not already exist; if so, that file is skipped. Finally, after all the tests have passed we mv the old name to the new.&lt;BR /&gt;&lt;BR /&gt;Note the "'s around each filename. Whitespace is perfectly legal (if dumb) in UNIX pathnames.&lt;BR /&gt;&lt;BR /&gt;This should be a robust solution.</description>
      <pubDate>Tue, 21 Feb 2006 22:02:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961733#M101177</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-02-21T22:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961734#M101178</link>
      <description>for file in *&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; mv $file `echo $file | perl -ple 's/\://g'`&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;==&lt;BR /&gt;&lt;BR /&gt;Simply as,&lt;BR /&gt;&lt;BR /&gt;for file in `ls`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  mv ${file} $(echo ${file} | perl -pe 's/://g')&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Muthu</description>
      <pubDate>Tue, 21 Feb 2006 22:50:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961734#M101178</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2006-02-21T22:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961735#M101179</link>
      <description>There is no need to negate with \ for : character. IT is needed for * ? \ / characters. Simply use s/://g is enough for pattern change.&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Muthu</description>
      <pubDate>Tue, 21 Feb 2006 22:53:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961735#M101179</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2006-02-21T22:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961736#M101180</link>
      <description>Because it needs to be done a gazzillion times (well somewhere between 100000 and 1000000) am I correct in assuming that the over head of starting perl as opposed to tr would be a factor in the load it places on the machine?&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2006 23:00:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961736#M101180</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2006-02-21T23:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961737#M101181</link>
      <description>Hi David, &lt;BR /&gt;&lt;BR /&gt;For processing large number of files, perl is the best way to go. It has proven ability when it comes to large number. &lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Tue, 21 Feb 2006 23:11:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961737#M101181</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-02-21T23:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961738#M101182</link>
      <description>Dear Arun - If the whole script was Perl I know you would be right but in this instance the majority of the file handling is done by the shell which invokes perl for every file name.  Hence my question about the overhead of "invoking" perl over tr.  I had assumed that tr would have less overhead because it is smaller but this is not the only factor.&lt;BR /&gt;&lt;BR /&gt;In the script that was processing these files I have changed the line that moves the file to read:&lt;BR /&gt;&lt;BR /&gt;mv $file $(echo "$dest/$file.$dayTimeStr" | tr ":" "_")&lt;BR /&gt;&lt;BR /&gt;(Looking at the script as a whole these days I would have written the whole script in perl which would no doubt have solved a lot of problems and made it a lot easier to maintain.)</description>
      <pubDate>Tue, 21 Feb 2006 23:25:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961738#M101182</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2006-02-21T23:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961739#M101183</link>
      <description>Perl is utilizing more cpu resource. It is good to go with default utilities like sed or tr or awk also.&lt;BR /&gt;&lt;BR /&gt;mv $file $(echo "$dest/$file.$dayTimeStr" | tr ":" "_")&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It is not good always.&lt;BR /&gt;&lt;BR /&gt;Use as,&lt;BR /&gt;&lt;BR /&gt;mv ${file} $(echo "${dest}/${file}.${dayTimeStr}" | tr ":" "_")&lt;BR /&gt;&lt;BR /&gt;It is good.&lt;BR /&gt;&lt;BR /&gt;PS: Do you want to remove : or change to _ ?&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Muthu&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2006 23:34:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961739#M101183</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2006-02-21T23:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961740#M101184</link>
      <description>If you want to maintain load then use tr method or sed instead of perl.&lt;BR /&gt;&lt;BR /&gt;mv ${file} $(echo ${file}| sed -e 's/://g' &lt;BR /&gt;&lt;BR /&gt;If you want to have SPEED use perl always.&lt;BR /&gt;&lt;BR /&gt;mv ${file} $(echo ${file}| perl -pe 's/://g'&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Muthu</description>
      <pubDate>Tue, 21 Feb 2006 23:36:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961740#M101184</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2006-02-21T23:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961741#M101185</link>
      <description>Hi David, &lt;BR /&gt;&lt;BR /&gt;You said, If the whole script was Perl I know you would be right but in this instance the majority of the file handling is done by the shell which invokes perl for every file name. Hence my question about the overhead of "invoking" perl over tr. I had assumed that tr would have less overhead because it is smaller but this is not the only factor.&lt;BR /&gt;&lt;BR /&gt;In the script that was processing these files I have changed the line that moves the file to read:&lt;BR /&gt;&lt;BR /&gt;mv $file $(echo "$dest/$file.$dayTimeStr" | tr ":" "_")&lt;BR /&gt;&lt;BR /&gt;When it comes to handle lot of files, i dont think unix default utilities will play a big part. I am not sure "tr" and "mv" are multithreaded as well. Perl with combination Unix shell utilities is a good way to strike. &lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Tue, 21 Feb 2006 23:39:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961741#M101185</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-02-21T23:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961742#M101186</link>
      <description>Hi Daavid,&lt;BR /&gt;&lt;BR /&gt;After careful deliberation, it looks like you need to replace the colon characters and rename the files.&lt;BR /&gt;&lt;BR /&gt;Here's an awk construct that would help. It assumes that your curent working dir is the one that has a guzzillion of those tiny files.&lt;BR /&gt;&lt;BR /&gt;# ls -1 | awk '{x=$0;gsub(":","");system("mv "x" "$0)}'&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
      <pubDate>Wed, 22 Feb 2006 11:38:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961742#M101186</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-02-22T11:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961743#M101187</link>
      <description>You need to recognize that your real bottleneck in this case is not Perl/Shell/external commands but rather the large (I assume a gazzilion is a large number) number of entries in a directory. The overhead of safely rewriting each directory entry is quite high. UNIX has to make certain that no other processes are altering the directory at the same time. Even if written in very tight C this would still be a time-consuming operation. On the other hand, this sounds like a one-time deal so let it run all night or over a weekend and declare victory.</description>
      <pubDate>Wed, 22 Feb 2006 12:47:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961743#M101187</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-02-22T12:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: simplest way to strip a character from a filename</title>
      <link>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961744#M101188</link>
      <description>Dear All,&lt;BR /&gt;&lt;BR /&gt;Thanks for the responses.&lt;BR /&gt;&lt;BR /&gt;I managed to replace the colons in about 90000 file names and fix the script that was responsible for creating them.&lt;BR /&gt;&lt;BR /&gt;Clay, your last post improved my understanding of why it was taking so long a lot.&lt;BR /&gt;&lt;BR /&gt;It did not help that the machine was out of disk space (hence my renaming requirement - I needed to archive the offending files to a Windows environment where colons in file names are verboten.)  At one point I was getting errors doing the actual rename because of the lack of disk space.&lt;BR /&gt;&lt;BR /&gt;I would probably still be trying to pull my hair out if if it were not for this forum.</description>
      <pubDate>Wed, 22 Feb 2006 19:21:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/simplest-way-to-strip-a-character-from-a-filename/m-p/4961744#M101188</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2006-02-22T19:21:51Z</dc:date>
    </item>
  </channel>
</rss>

