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
Sunday, April 29, 2007
Search and replace Shell Script
Had to parse 100's of files in a loop and replace a word
called Bombay with a new word Mumbai
cat file1.dat
city name is Bombay and country is INDIA.
To:
cat file1.dat
city name is Mumbai and country is INDIA.
called Bombay with a new word Mumbai
cat file1.dat
city name is Bombay and country is INDIA.
To:
cat file1.dat
city name is Mumbai and country is INDIA.
for file in /tmp/a /tmp/c /tmp/b ; do
sed 's/Bombay/MUMBAI/g' ${file} > ${file}.new
done
Subscribe to:
Posts (Atom)