Sponsored Content
Top Forums Shell Programming and Scripting Rename all files (filename with spaces) to different extension Post 302655245 by mac4rfree on Wednesday 13th of June 2012 02:50:01 AM
Old 06-13-2012
Rename all files (filename with spaces) to different extension

Hi,

I have files with filenames as below.

Code:
SGM Daily Sales Email-en-us-05312012.xlwa

I want to rename it in .xls. I am writing a script to change this, as there can be multiple files in subfolders.

I have the following script.

Code:
#!/bin/ksh
for oldfile in $(find /usr/local/data/vstar/report_repository -name "*.xlwa")
do
newfile="$(echo $oldfile | sed 's/.xlwa/.xls/g')"
mv "$oldfile" "${newfile}"
done

this is the log of it.

Code:
find /usr/local/data/vstar/report_repository -name "*.xlwa"
++ find /usr/local/data/vstar/report_repository -name '*.xlwa'
+ for oldfile in '$(find /usr/local/data/vstar/report_repository -name "*.xlwa")'
echo $oldfile | sed 's/.xlwa/.xls/g'
++ echo /usr/local/data/vstar/report_repository/SGM/SGM
++ sed s/.xlwa/.xls/g
+ newfile=/usr/local/data/vstar/report_repository/SGM/SGM
+ mv /usr/local/data/vstar/report_repository/SGM/SGM /usr/local/data/vstar/report_repository/SGM/SGM
mv: cannot stat `/usr/local/data/vstar/report_repository/SGM/SGM': No such file or directory
+ for oldfile in '$(find /usr/local/data/vstar/report_repository -name "*.xlwa")'
echo $oldfile | sed 's/.xlwa/.xls/g'
++ echo Daily
++ sed s/.xlwa/.xls/g
+ newfile=Daily
+ mv Daily Daily
mv: cannot stat `Daily': No such file or directory
+ for oldfile in '$(find /usr/local/data/vstar/report_repository -name "*.xlwa")'
echo $oldfile | sed 's/.xlwa/.xls/g'
++ echo Sales
++ sed s/.xlwa/.xls/g
+ newfile=Sales
+ mv Sales Sales
mv: cannot stat `Sales': No such file or directory
+ for oldfile in '$(find /usr/local/data/vstar/report_repository -name "*.xlwa")'
echo $oldfile | sed 's/.xlwa/.xls/g'
++ echo Email-en-us-05312012.xlwa
++ sed s/.xlwa/.xls/g
+ newfile=Email-en-us-05312012.xls
+ mv Email-en-us-05312012.xlwa Email-en-us-05312012.xls
mv: cannot stat `Email-en-us-05312012.xlwa': No such file or directory

So whenever there is a space in the filename, it is taking as a different file..

Could somebody help me out here..

Cheers!!!!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving files with spaces in filename from one directory to another

Hello, When I run following script #!/bin/bash cd ~/directory1 mv `ls -trF | grep -v / | tail -10 ` ~/directory2 works fine with filenames not having any space but runs into issues with filenames that have spaces tried with $file variable still doesnot work. Can someone help me (4 Replies)
Discussion started by: asakhare
4 Replies

2. Shell Programming and Scripting

how to rename all files that have a certain text in the filename using tcsh shell

Hello~ I'm on AIX version 5 and I believe I have the tcsh shell environment to play in. Can you guys help me with a solution to rename all files that have "eclp" in the filename to "ecl" ? I basically want to rename the files and strip the "p" out. i.e. original filenames: ... (3 Replies)
Discussion started by: in2vtec
3 Replies

3. Shell Programming and Scripting

copying files with spaces in the filename

Hi I am having difficulty copying files from one dir to another due to a space in the names of the file with an extension .rtf There are a group of files and the command am using is cp `ls -rt /wlblive/home/whiops/ops/RTFs/*.rtf|head -20` /wlblive/home/jamshed Since the files are... (3 Replies)
Discussion started by: jamshedj
3 Replies

4. Shell Programming and Scripting

List files with spaces in filename

I have a text file containing files in a directory structure i.e. /project/hr/raw/jcpdatav/datav_aug03 /project/hr/raw/jcpdatav/comb8121sep02n /project/hr/raw/jcpdatav/datav_feb04_ons /project/hr/raw/jcpdatav/corpsick_jun06 /project/hr/raw/jcpdatav/jcpjoiners200507... (3 Replies)
Discussion started by: mr_crosby
3 Replies

5. Shell Programming and Scripting

ksh command to rename all files with no extension

hi! i want to rename all files with no extension with the extension DAT. with this command ls |grep -v "\\." i can list files but i dont know how i am going to rename them.. so i tried FILE_LIST=ls |grep -v "\\." for TEST_FILE in ${FILE_LIST} do mv $TEST_FILE... (2 Replies)
Discussion started by: kouppoua
2 Replies

6. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

7. UNIX for Dummies Questions & Answers

Rename multiple files, changing prefix, extension and dropping characters

I'm currently only able to perform some very basic functions, so hope this makes sense... I have a set of about 27 files that need to be renamed from something like this: 000012ABCDEFGHIJ.XXX.YYY.ZZZ 000078KLMNO.XXX.YYY.ZZZ 000099PQ.XXX.YYY.ZZZ to something like this: newa012.abc... (11 Replies)
Discussion started by: bbmcg
11 Replies

8. Red Hat

How to rename files to files with mv extension?

currently in my directories $ ls -lrth total 32K -rw-r--r-- 1 oracle oinstall 864 Feb 25 16:01 cor_bin_gateway_cnt.sql -rw-r--r-- 1 oracle oinstall 782 Feb 25 16:01 mer_bin_gateway_cnt.sql I want to rename files with *.sql to *.mv extension, but when I execute the following $ mv... (1 Reply)
Discussion started by: jediwannabe
1 Replies

9. Shell Programming and Scripting

Creating Multiple data files with spaces in the filename

Hi, I have a list of filenames in the format with Spaces in the filename. As an example : Sample File 1.txt Sample File 2.txt Sample File 3.txt.....I have about 100 files like this. I am trying to create a block of code or use an available command to a) Create a file b) Put in some... (2 Replies)
Discussion started by: ban3rj33
2 Replies

10. Shell Programming and Scripting

Bash to rename files repeats previous filename in directory

In the below bash processes substitution, if there are 3 files in a directory /home/cmccabe/medex.logs/analysis.log, the filename variable is set to where these files are located. The code does execute, the problem is that if there is a renamed file in the output directory below, it gets... (0 Replies)
Discussion started by: cmccabe
0 Replies
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 04:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy