Hi,
can anyone have a ksh script to rename multiple files (ie to remove .Z extension of the files)
can someone correct this?
for i in *.Z
do
var1 = substr($i, 1,at(".Z",$i)-1)
mv $i $var1
done
Thanks..
Antony
Hi,
can anyone have a ksh script to rename multiple files (ie to remove .Z extension of the files)
can someone correct this?
for i in *.Z
do
var1 = substr($i, 1,at(".Z",$i)-1)
mv $i $var1
done
Thanks..
Antony
The following does a copy; you can change to the move (mv) command
> cat copy_csv
#! /bin/bash
for i in *.csv
do
var1=$(basename "$i" .csv)
cp $i $var1
done
Another one:
ls *.Z|sed 's/\(.*\)\.Z/mv & \1/'|sh
Try this first to be shure you get the right files before sh do the job:
ls *.Z|sed 's/\(.*\)\.Z/mv & \1/'
Regards
for i in *.Z
do
mv $i ${i.Z}
done
Replace
mv $i ${i.Z}
with
mv $i ${i%.Z}
hi
Thanks for your reply.But I would like to use substring operation.
Thanks
hi
Thanks for your reply.But I would like to use substring operation.
Thanks
for file in `ls *.Z`
do
filename=\`ls $file | cut -f1 -d"."\`
mv $filename.Z $filename.X
done
Thanks a lot. it works well
acn you explain this to me ?
ls *.Z|sed 's/\(.*\)\.Z/mv & \1/'
\(.*\)
A saved substring wich can be recalled with \1
\.Z
Sed use a greedy match so it saves the part before the last "." in the substring
This isolated every characters after the "." from the substring
mv & \1
This gives the mv command, the ampersand makes it possible to reference the entire match in the replacement string.
Regards
Thanks a lot. is it possible to do the same thing using the substr operation.?
Antony.
Coincidentally, there's a rename command in Unix.
$ rename -n 's/\.z//' *.z
test1.z renamed as test1
test2.z renamed as test2
test3.z renamed as test3
Note: Remove the "-n" to actually do it -- the flag just shows what would be done.
ShawnMilo
-----------------------------
Hi!!
Could u explain how the script is working?
ls .Z|sed 's/\(.\)\.Z/mv & \1