However, this might be me being very dumb, but is there a way of 'saving' this new file name to the original. And could this then be automated to do more than one file at a time. Sorry I'm a bit new to this.
I see the new files being created (They are quire big so they take a while)
However the file names produced as a result of the loop aren't changed (they come out exactly as they went in). It's really making me scratch my head. I think the problem's 99% sorted but somethings' wrong.
When I run it sends the whole content of the files in the directory to the screen
[quote]
If the output is correct you can pipe the output of the sed command to sh to mv the files in the loop as follow:
for file in *.txt
do
sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/mv & \1\3-\2\4/' "$file" | sh
done
Regards
[quote]
When I run it, this comes up and the filenames are unchanged
sh: llllll: not found
sh: l: not found
sh: lllllllllllllllllll: not found
sh: rrrrrrrrrrrrrrrr: not found
sh: rrrrrrrrrrrrrrrrr: not found
sh: rrrrrrrrrrrrrrrrr: not found
sh: rrrrrrrrrrrrrr: not found
Where llllllllllllllll and rrrrrrrrrrrrrrrrrr etc are the contents of some dummy files I'm using to verify the scripts
I was assuming that you have only .txt files with names in the same format.
To select filenames with a format like "daf_1961-04_act.txt" you can do something like:
for file in `ls | grep ".*_....-.._.*"`
do
sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/mv & \1\3-\2\4/' "$file"
done