[SOLVED] moving multiple files? mv

HI I have a list of files that are incorrectely names and I need to move them to new name .. I tried few things that has not worked so far can you help ?

I need to rename all thes eifle ( tere are over 100 )

xldn0357bap.orig.new
xldn0389bap.orig.new
xldn0439bap.orig.new
xldn0475bap.orig.new

to

xldn0357bap.orig
xldn0389bap.orig
xldn0439bap.orig
xldn0475bap.orig

How can I use a move command to do this?

In any Bourne compatible shell (e.g., bash, ksh, sh):

for i in *.new
do
    mv "$i" "$(basename "$i" .new)"
done
IFS="."
for FILE in *.new
do
        set -- "$FILE"
        echo mv "$FILE" "$1.$2"
done

Remove the echo once you've tested and are sure it does what you want.

for fname in `find . -name "xldn*bap.orig.new"`
do
fname1=`basename $fname | cut -d"." -f1`
fname2=$fname1".orig"
mv $fname $fname2
done

That is a dangerous use of backticks, better rewritten as

find ... | while read FILENAME
do
        ...
done
1 Like
 ls *.new | sed 's/\(.*\).new/mv & \1/' | sh

I believe you have only those files that needs to be moved in the directory where you are going to execute above

Do you have a pattern matching both old and new filename set. If yes, you can use the find command with mv in -exec option

 
#!/bin/ksh
for i in *.new
do
    mv "$i" "${i%*.new}"
done
 

Thanks msabhi...prior to this example I was assuming that it is not possible to use shell commands inside sed.
Could you please tell about some shell commands that could be used inside sed ?

He's not.

Leave the | sh off the end to see what it does.

Yes as corona pointed out, am not using any shell command inside sed there...i am just executing whats thrown out by sed...
My knowledge is limited on usage of shell commands inside sed..but from what i remember from my experience, we can use some commands like echo inside sed like below

sed "1i `echo FIRST`" tmp_file 

But you can't use cat command inside sed or i have failed trying to use cat command inside sed..

1 Like

Ah..Great...
Thanks Corona...learnt something new today !!

all these commands were helpful and I used thell
Cheers