guys,
i am writing a .ksh file to ssh to a remote machine and change all occurances of .ixf to .WIP like this :
-->>> for i in *.ixf do echo $i done mv $i $i.WIP exit <<---
--> this returns .ixf.WIP - i can live with that.
then i need to sftp from another remote machine, copy the files across to the new box and rename the file back to .ixf like this :
-->> for i in *.WIP; do echo $i; done; mv $i $i.ixf <<--
--> this returns .ixf.WIP.ixf - i can't live with this.
I need to strip WIP.ixf from the end, i think using awk but cannot get the syntax correct.
Any help here would be appreciated.
Thanks
n1djs
2
I assume this is a unix box...
awk is a nuclear bomb, when all you need is a hammer.
Use basename (see example below)
#!/bin/ksh
for i in *.ixf; do
name=$(basename $i .ixf)
echo $name
mv $i $name.WIP
done
If using 'sed ' is an option:
for i in *.WIP; do
echo $i
mv $i `echo $i | sed 's/\..*$//'`.ixf
done
Or if you want (GNU) awk, and assuming the 1st dot in the filename separates all the extension(s):
for i in *.WIP; do
echo $i
mv $i `echo $i | gawk -F . '{print $1}'`.ixf
done
HTH,
Zsoltik@
for i in *.WIP
do
echo $i
OUTFILE=$(echo ${i%(\.[A-Z]*)}
mv $i $OUTFILE
done
danmero
5
He need to remove the extension.
for i in *.WIP
do
mv $i `echo $i | sed 's/\.WIP$//'`
done