The file names currently all start with '0000', then a 2-digit value, then a name that can be anywhere from 2 to 10 characthers, then the same extension. They need to be changed to a new prefix + 0 + the existing 2 digit value, dropping the next 2 to 10 characters, and changing the extension on each file to the new one. All are case sensitive as indicated.
I was able to use one-liners to get to a file name like 'newa012PQ.abc', and am having the most trouble trying to understand how to drop the 'PQ' etc.
As I said I'm not familiar with much of this and see a lot of references to sed and awk etc. but short of copying code I'm not sure the meaning of, or messing with scripting that I've never touched before I figured I'd try here first.
@neutronscott - I'm assuming that I would use this in a script??? If this is something we'd have to run infreuqently I'm guessing that makes more sense just not sure how to do that.
Anyhoo... @Peasant - running the command in the working directory using your code works!!! I did take your advice @Corona688 - and piped to 'cat' instead of 'sh' first then via 'sh' and I see what it does, but can someone explain more what it's doing one vs the other?
Thanks to all again. This has been most helpful and very much appreciated!!!
I suppose that's OK if your filenames have absolutely no chance of containing whitespace or special characters. It's not good practice to parse ls or evaluate user data.
Probably the command was copied wrong. Did you try post #3?
proof of concept
$ ls -l
total 0
-rw-r--r-- 1 mute mute 0 May 17 17:34 bad file?echo fail
$ ls -1 | sed 's/\(^0\{1,4\}\)\([0-9][0-9]\)\(.*\)/mv & newa0\2.abc/ ' | sh
sh: bad: not found
fail
The filenames are the same every day but I've been reading about concerns using 'ls' so now I'm a little worried. There are other files in this directory, though they are not named anything similar in prefix or extension. When running
ls -1 | sed 's/\(^0\{1,4\}\)\([0-9][0-9]\)\(.*\)/mv & newa0\2.abc/ ' | sh
it returns
sh: line 7: ./(other file names here): Permission denied
I reran this
for file in 0000*; do new=${file#0000}; new=newa0${new:0:2}.abc; echo mv "$file" "$new"; done
[/FONT]and I was copying the $ at the beginning before but when I dropped that it allows me to see the correct results...But to use this, I'm still not understanding how I then get it to run to actually change the file names rather than just showing it?