Showing posts with label For Loop. Show all posts
Showing posts with label For Loop. Show all posts

Sunday, April 29, 2007

Replace .htm with .html in 100's of files inside a dir

I needed to replace {.htm} files with {.html} extensions in
100's of files in a directory :

Heres what I did :

[root@unixguy scripts]# ls
file1.htm file2.htm file3.htm

[root@unixguy scripts]# for list in `ls -1t *.htm*`
> do
> prefix=`echo $list | awk -F"\." '{print $1}'`
> mv $list ${prefix}.html
> done


[root@unixguy scripts]# ls
file1.html file2.html file3.html


One more way of doing this :

[root@unixguy scripts]# ls
file1.html file2.html file3.html

[root@unixguy scripts]# ls *.html | awk -F '.'
'{print "mv "$1".html "$1".htm"}'| csh

[root@unixguy scripts]# ls
file1.htm file2.htm file3.htm