ranga27
1
Hello
I am currently working on a shell script which actually needs to pull some file
from a server ,
The filenames will have the extension with date/time stamp , i need to trim that and name it to proper format
Example :
xyz_20091108_22142365.gzip
i need to remove the numbers from that and name it to xyz.gzip
i know i can use mv for these but i have huge number of files with different names and with different time stamps .
Please suggest a method to trim the numeric values(date/timestamp) without using a mv command.
Thanks for your help!!
file=xyz_20091108_22142365.gzip
newfile=${file%%_*}.gzip
Or, if the suffix could change:
file=xyz_20091108_22142365.gzip
newfile=${file%%_*}.${file##*.}
ranga27
3
Thanks for your reply,,
it displays the file name , but i need to have the new file name in the directory instead of the one which has the timestamp
xyz_20091108_22142365.gzip should be replaced by xyz.zip in the same directory
but it displays the file name but the actual file is not there.
Thanks for your help again !!
ranga27
5
Thanks for your reply :
if the file name is xyz_xyzxyz_xyz_2009565213_20085778992_.lst.gzip
can you please let me know can you you trim the numeric values
output should be :
xyz_xyzxyz_xyz.lst.gzip
Thanks again!
panyam
6
something like this:
echo "xyz_xyzxyz_xyz_2009565213.lst.gzip" | sed 's/_[0-9][_0-9]*//g'