Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Rename file extension in script
Name: hismail Date: May 19, 2008 at 00:33:29 Pacific OS: Linux Redhat CPU/Ram: 4gb/2/gb Product: HP
Comment:
Hi, I would like to rename files in a directory. for eg: ls -ltr *.bup.* would give a result of: ma.bup.Wednesday hw.bup.Wednesday etc I need to trim the last field i.e "Wednesday" to just ma.bup automatically everyday
Name: nails Date: May 19, 2008 at 13:33:39 Pacific
Reply:
One way is to use the ksh/bash pattern matching operators. Change the cp to mv once you get the script working the way you want:
#!/bin/ksh
f=ma.bup.wed
v=${f%.*}
cp $f $v
0
Response Number 2
Name: hismail Date: May 19, 2008 at 23:43:18 Pacific
Reply:
Hi Nails I tried this: for f in *.Friday do mv $f ${f%*.} done but all it does it is puts an extra .bup after my original file?? I need to trim the file to just have "ma.bup" & not ma.bup.Friday.bup
thanks Hamim
0
Response Number 3
Name: nails Date: May 20, 2008 at 08:37:15 Pacific
Summary: How may I rename files *.txt to *.dat? (*=all). Example: If i have 3 files named a.txt, b.txt, c.txt how can I rename them as a.dat, b.dat & c.dat (at the same time, not one by one). I know ...
Summary: Greetings! Does anyone know of a utility or a script for renaming files on a UNIX web server? I've seen several of these types of renaming utilities for Windows, but none for UNIX. I have 10,000 fil...
Summary: Looking for some help in renaming files using a shell script. Suppose I have a directory which contains several files, some of which are *.dat files. If there are 7 *.dat files, I would like to rename...