|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
i need to change a filename from a ksh script based on the suffix of the filename. In my particular situation I'm looking in a directory and if the filename ends in _20.dat i need to change it to end with _2.dat and keep the part of the filename that precedes the _20.dat as part of the _2.dat filename. For example abcd_ef_20.dat woud become abcd_ef_2.dat. Any help would be greatly appreciated!
thanks, Rick |
|
#2
|
||||
|
||||
|
If you know the number just before the extension is a predictable number, you should be able to do this:
Code:
for file in *
do
mv $file ${file%20.dat}2.dat
done
|
|
#3
|
|||
|
|||
|
Does that not pre-suppose that all the files in the directory should be renamed?
|
|
#4
|
||||
|
||||
|
I was just using it as a basic example. It isn't hard to exclude files from the list. Just modify the for statement like so:
Code:
for file in *20.dat |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Change filename based on knowing only part of existing file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|