Hi everyone,
I have a file called pdf.txt which has the following list inside:
7110412_1_31122012.pdf
7286510_4_46667100.pdf
4002176_1_00018824.pdf
...
I need a looping script to REMOVE the 8th and 9th character of the filenames listed, no matter what character that is.
So example:
7110412_1_31122012.pdf
will be
7110412_31122012.pdf
(_1 was deleted)
I did the following but it hangs:
for file in `cat pdf.txt`
do
r=$(echo $file | cut -c 8-9)
new=$(tr -d "$r")
mv "$file" "$new"
done
Please help, thanks!
cut -c1-7 -c10- pdf.txt > newpdf.txt
thanks for the quick response pseudocoder, however,
the listed files are really filenames located say, on /home/apps/pdf2010 directory.. i need to change the filename (with the format i mentioned above) that are in that directory by removing the 8th and 9th char
sorry for the confusion
All right, try this, directly in the target directory:
$ for i in *.pdf
do
j=$(echo "$i" | cut -c1-7 -c10-)
mv "$i" "$j"
done
Please make a backup of your original files before you run this, just for the case that something goes wrong
actually i tweaked it a little to work:
for i in *.pdf
do
j=$(echo "$i" | cut -c1-7,10-)
mv "$i" "$j"
done
thanks a lot pseudocoder! :):)