Hi Guys,
I need a help. I have 1130 zip files. Each one of them has files including 1 html file with long file name (includes special charactors, Alphabetic and numbers).
I have copied all 1130 zip files to my linux system and extracted using below command.
Find . -name "*.zip" -exec unzip {} \;
Now, I have got 1130 folders, each of them has files including 1 html files with long name as I told earlier.
All I want now, I want to find all html files and rename it in the same folder (i.e abc.html), because since It's html files I don't want to move this files to different folder.
I tried this command going to each of the folder. It works.
mv [file_name.html] abc.html
or
rename [A-z,0-9]*.html abc.html *.html
but how long this will take to do it for 1130 folder :rolleyes:.
Please I need a script to do all at once.
Thanks,
Rajmani
I would suggest
- do a find for all the html files from the directory where the files will be there
- store the o/p in a file
- in a shell script, read the file line by line with a variable counter set to increment for each line read
- mv $readline $var.html
cheers,
Devaraj Takhellambam
Hi Devaraj,
Thanks for your reply.
Here is the example of "html" file which each one of the folder contains;
UJResults.aspx?sToDay=0&sToMonth=10&sToYear=2002&sCivilCriminal=Both&sFromDay=0&sFromMonth=10&sFromYear=2002&sJudgementNumber=&iHearingType=&iSubject=&sOffenceType=&sJudge=&sDivision=&iCourtID=&sParties=&Exact=False.1.html
I don't know, the idea works for this long file name.
I am beginner to the script, If you give me more input. It would be great.
Thanks for your help.
do something like
#!/bin/ksh
mkdir htmlfiles
find . -name "*.html" -print 2>/dev/null 1>findlist
i=1
while read file
do
mv $file htmlfiles/$i.html
i=`expr $i + 1`
done < findlist
echo $i
cheers,
Devaraj
It doesn't work.
mv: target `htmlfiles/1.html' is not a directory
mv: target `htmlfiles/2.html' is not a directory
mv: target `htmlfiles/3.html' is not a directory
However "htmlfiles" directory created is part of the script.
I really don't want to move these files to "htmlfiles" directory, since this html has supporting image files in the directory. I have just wanted to find and rename in the same directory.
is there anythink like this to rename and save in the directory.
find . -name "*.html" |xargs rename .html abc.html *.html
Are you ok giving the same name to all these files?
If so, I believe you could just do a
find . -type f -name "*.html" -exec mv {} abc.html \;
or
find . -type f -name "*.html" | xargs mv abc.html
Hi Devaraj,
Finaly I have done with it. Thanks for your help.
Here is the actual script I wanted.
#!/bin/sh
find . -name ".zip" -exec unzip {} \;
find . -name ".zip" -exec rm {} \;
for file in ;
do
if [ -d $file ]; then
cd $file; rename [A-Z,a-z,0-9,_,=,].html abc.html *.html
cd ..
mv $file htmlfile
fi
done
Regards,
Rajmani
Glad to know that it is working for you now