<?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: Change filename with awk in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510775#M38491</link>
    <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Almost the same as JRF's but with no assumption on the number of subsequent spaces :&lt;BR /&gt;&lt;BR /&gt;ls *\ * | awk '{ name = $0 ; gsub ( /  */, "_" ) ; printf ( "mv \"%s\" %s\n", name, $0 ) }' | ksh&lt;BR /&gt;&lt;BR /&gt;Be careful there are two spaces in /  */&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Jean-Philippe</description>
    <pubDate>Fri, 09 Oct 2009 14:53:08 GMT</pubDate>
    <dc:creator>Jean-Philippe Henry</dc:creator>
    <dc:date>2009-10-09T14:53:08Z</dc:date>
    <item>
      <title>Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510770#M38486</link>
      <description>I need to rename a series of files that contain spaces in their names.&lt;BR /&gt;&lt;BR /&gt;Batch(6)_9_25_2009 4-22-25 PM.pdf&lt;BR /&gt;&lt;BR /&gt;I would like to replace the spaces with the underscore character.&lt;BR /&gt;&lt;BR /&gt;Batch(6)_9_25_2009_4-22-25_PM.pdf&lt;BR /&gt;&lt;BR /&gt;Or possibly remove all underscore characters and spaces.&lt;BR /&gt;&lt;BR /&gt;Batch(6)925200942225PM.pdf&lt;BR /&gt;&lt;BR /&gt;I know awk can handle this, but unfortunatly the specific command syntax is a little outside my awk experience.</description>
      <pubDate>Thu, 08 Oct 2009 20:31:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510770#M38486</guid>
      <dc:creator>John Carver</dc:creator>
      <dc:date>2009-10-08T20:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510771#M38487</link>
      <description>John:&lt;BR /&gt;&lt;BR /&gt;Variously, 'sed' or 'awk' or Perl will do:&lt;BR /&gt;&lt;BR /&gt;# X="Batch(6)_9_25_2009 4-22-25 PM.pdf"&lt;BR /&gt;&lt;BR /&gt;# echo ${X}|sed -e 's/ //g'&lt;BR /&gt;&lt;BR /&gt;# echo ${X}|awk '{gsub(/ /,//,$0);print}'&lt;BR /&gt;&lt;BR /&gt;In the 'awk' snippet, if you wanted to confine your substitution to a particular field then you could use the appropriate field number ( other than $0).&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Oct 2009 21:51:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510771#M38487</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-08T21:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510772#M38488</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oops; I bungled the 'awk'.  Too, you may not want to collapse spaces, but rather to substitute a space with an underscore.&lt;BR /&gt;&lt;BR /&gt;# echo ${X}|sed -e 's/ /_/g'&lt;BR /&gt;&lt;BR /&gt;Awk is a bit odd in the way it defines the arguments to 'gsub'.  Use this:&lt;BR /&gt;&lt;BR /&gt;# echo ${X}|awk '{gsub(/ /,"_",$0);print}'&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>Thu, 08 Oct 2009 22:04:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510772#M38488</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-08T22:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510773#M38489</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;Perl snippet.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;      $commandline = "cp ${filetoback} ${filetoback}.bck";&lt;BR /&gt;      system("${commandline}");&lt;BR /&gt;$commandline = "sed s/investmenttool.com/isnamerica.com/g ${filetoback} &amp;gt; $filetoback.bck";&lt;BR /&gt;      print ("Converting: ${convertiasbackupdir}${filetoback}\n");&lt;BR /&gt;      print LOGF ("Converting: ${filetoback}\n");&lt;BR /&gt;      system("${commandline}");&lt;BR /&gt;      $commandline = "cp ${filetoback}.bck ${filetoback}";&lt;BR /&gt;      system("${commandline}");&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Basically uses the sed to change the contents of a file.&lt;BR /&gt;&lt;BR /&gt;To merely change the name a mv command can do the job.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Thu, 08 Oct 2009 23:28:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510773#M38489</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2009-10-08T23:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510774#M38490</link>
      <description>Hello.&lt;BR /&gt;&lt;BR /&gt;Much better to use mmv or prename (might be called something else in your distribution - it's a handy Perl script).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Goran</description>
      <pubDate>Fri, 09 Oct 2009 04:04:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510774#M38490</guid>
      <dc:creator>Goran Koruga</dc:creator>
      <dc:date>2009-10-09T04:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510775#M38491</link>
      <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Almost the same as JRF's but with no assumption on the number of subsequent spaces :&lt;BR /&gt;&lt;BR /&gt;ls *\ * | awk '{ name = $0 ; gsub ( /  */, "_" ) ; printf ( "mv \"%s\" %s\n", name, $0 ) }' | ksh&lt;BR /&gt;&lt;BR /&gt;Be careful there are two spaces in /  */&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Jean-Philippe</description>
      <pubDate>Fri, 09 Oct 2009 14:53:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510775#M38491</guid>
      <dc:creator>Jean-Philippe Henry</dc:creator>
      <dc:date>2009-10-09T14:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510776#M38492</link>
      <description>Almost there. I've incorporated sed into a bash script. There might be just one Batch* file or many, thus the need for a loop. mv would be my first choice but fails after trying to change one var to another. I've tried the "line" variable with and without the quotes.&lt;BR /&gt;&lt;BR /&gt;ls Batch* | while read line&lt;BR /&gt;do&lt;BR /&gt;change=`echo ${line}| sed -e 's/ /_/g'`&lt;BR /&gt;mv \"$line\" $change&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Try `mv --help' for more information.&lt;BR /&gt;mv: when moving multiple files, last argument must be a directory&lt;BR /&gt;Try `mv --help' for more information.&lt;BR /&gt;mv: when moving multiple files, last argument must be a directory&lt;BR /&gt;Try `mv --help' for more information.&lt;BR /&gt;mv: when moving multiple files, last argument must be a directory</description>
      <pubDate>Fri, 09 Oct 2009 17:30:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510776#M38492</guid>
      <dc:creator>John Carver</dc:creator>
      <dc:date>2009-10-09T17:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510777#M38493</link>
      <description>&amp;gt;I've tried the "line" variable with and without the quotes.&lt;BR /&gt;mv \"$line\" $change&lt;BR /&gt;&lt;BR /&gt;Change to actually use quotes: mv "$line" $change&lt;BR /&gt;</description>
      <pubDate>Sun, 11 Oct 2009 01:34:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510777#M38493</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-10-11T01:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Change filename with awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510778#M38494</link>
      <description>Thanks for the help. My script can now rename the filenames.</description>
      <pubDate>Mon, 12 Oct 2009 17:25:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-filename-with-awk/m-p/4510778#M38494</guid>
      <dc:creator>John Carver</dc:creator>
      <dc:date>2009-10-12T17:25:43Z</dc:date>
    </item>
  </channel>
</rss>

