Rename Filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename Filenames
# 8  
Old 11-21-2014
I think I see the problem. You put the code in a script, made it executable. When you open it in your file manager you get asked if you want to "Run in Terminal", "Display", Cancel, Run, right? You clicked run in terminal, but the processing of the 6 files was too fast to see anything.

Either you run the script in a terminal (NOT from file manager) or you add sleep 5 at the end of the script and try again.

Oh, one other thing, you said your files are like SG1130113000247.CAPNFXS, but they are more like SG1130113000247.CAPNFXS.csv Smilie
If you want the output to be 130113000247, both scripts will produce right output.
If you want the output to be 130113000247.csv, substitute "$new" with "$new.csv"
# 9  
Old 11-21-2014
Quote:
Originally Posted by junior-helper
I think I see the problem. You put the code in a script, made it executable. When you open it in your file manager you get asked if you want to "Run in Terminal", "Display", Cancel, Run, right? You clicked run in terminal, but the processing of the 6 files was too fast to see anything.

Either you run the script in a terminal (NOT from file manager) or you add sleep 5 at the end of the script and try again.

Oh, one other thing, you said your files are like SG1130113000247.CAPNFXS, but they are more like SG1130113000247.CAPNFXS.csv Smilie
If you want the output to be 130113000247, both scripts will produce right output.
If you want the output to be 130113000247.csv, substitute "$new" with "$new.csv"
Terminal shows:

Code:
mv SG1130113001247.CAPNFXT.csv 130113001247.csv
mv SG1130113002247.CAPNFXU.csv 130113002247.csv
mv SG1130113003246.CAPNFXV.csv 130113003246.csv
mv SG1130113004247.CAPNFXW.csv 130113004247.csv
mv SG1130113005247.CAPNFXX.csv 130113005247.csv
mv SG1130113010247.CAPNFXY.csv 130113010247.csv

But in my folder, the filenames were not changed.

---------- Post updated at 08:21 AM ---------- Previous update was at 08:20 AM ----------

Quote:
Originally Posted by Chubler_XL
Try this command from your folder and post output:

Code:
printf "\"%s\"\n" *SG1*

Code:
[root@localhost rename]# printf "\"%s\"\n" *SG1*
"SG1130113001247.CAPNFXT.csv"
"SG1130113002247.CAPNFXU.csv"
"SG1130113003246.CAPNFXV.csv"
"SG1130113004247.CAPNFXW.csv"
"SG1130113005247.CAPNFXX.csv"
"SG1130113010247.CAPNFXY.csv"

# 10  
Old 11-21-2014
It isn't going to do anything until you change the line:
Code:
       echo mv "$file" "$new"

to:
Code:
       mv "$file" "$new"

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Slackware

cp does not like filenames with accents?

Hi: mkisofs -graft-points -rational-rock -joliet -joliet-long -full-iso9660-filenames -iso-level 2 -o /tmp/image.iso STORE1/=/almacen/strauss In /almacen/strauss there are filenames containing not only spaces but accented characters as well. I burned the image to DVD, with the result that all... (2 Replies)
Discussion started by: stf92
2 Replies

2. Shell Programming and Scripting

get filenames from log

Hi. I'm trying to get the names of files from a log file, without the path and special characters. I have a file that contains lines like this: '/path/to/files/file00010000070874.EXT' '/path/to/files/file00010000070875.EXT' '/path/to/files/file00010000070876.EXT'... (4 Replies)
Discussion started by: Hekm
4 Replies

3. AIX

filemon with no filenames...

i excuted filemon with filemon -u -o /tmp/filemon.out -O all;sleep 60; trcstop. everything is ok, but i only get PID for filenames in Most Active Files. is there any different flags i need to use to get filenames? Code tags please, thanks. (3 Replies)
Discussion started by: curtis911
3 Replies

4. Shell Programming and Scripting

Manipulating Filenames

Hi Folks, I'm looking for some ideas on how to change some file names. I'm pretty sure I need to use sed or awk but they still escape me. The files I have are like: VOD0615 NEW Blades R77307.pdf or VOD0615_NEW_Blades_R77307.pdf and what I want after processing is: R77307 NEW Blades.pdf ... (5 Replies)
Discussion started by: imonkey
5 Replies

5. UNIX for Dummies Questions & Answers

renaming filenames

I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (0 Replies)
Discussion started by: vpv0002
0 Replies

6. Shell Programming and Scripting

Extracting filenames

Hi I need to pull out the name of the file from the path. See, here is my loop that gets the files: dsxdir="/var/local/dsx/import" for dsxfile in $dsxdir/*.dsx; do dsxlog $reverb --info --module="$module" "$dsxfile" $dsximp $norule $oprange --dsn=$dsn --dbname=$dbname... (6 Replies)
Discussion started by: ladyAnne
6 Replies

7. UNIX for Dummies Questions & Answers

parsing filenames

How can I loose a part of the filename I want to drop the “_<Number>.sql” Below I have a listing of file names in a file Eg : CREDIT_DEL_033333.sql I want it to be CREDIT_DEL ATM_DEBIT_CARD_0999999.sql I want it to be ... (3 Replies)
Discussion started by: jville
3 Replies

8. Shell Programming and Scripting

Patterns in Filenames

Hi, To start, I am using a bash shell on a G4 powerbook running Leopard. I am attempting to write a shell script that will automate the processing of satellite imagery. All the filenames are of the following construction: A2008196000500.L2 where A indicates the sensor, the next four... (6 Replies)
Discussion started by: msb65
6 Replies

9. UNIX for Dummies Questions & Answers

How can I rename multiple files depending on a string occuring in the filenames?

I have many files that have "inputstring" somewhere in their filename (without the quotes), and I want to rename them all so that "inputstring" is replaced with "newstring". And I also want to specify arbitrary text for "inputstring" and "newstring" so that I can call the scripts that does this... (6 Replies)
Discussion started by: karman
6 Replies

10. Shell Programming and Scripting

spaces in filenames

I have a problem with the script below #!/bin/sh for vo in `find -maxdepth 1 -type f -regex "^\./*$"` do ls -l "$vo" some other commands done It works fine until `find ...` returns files with spaces. I've tryed to change IFS but haven't succeed Any solutions? (4 Replies)
Discussion started by: Hitori
4 Replies
Login or Register to Ask a Question