Operating System - HP-UX
1833256 Members
2851 Online
110051 Solutions
New Discussion

Date search/replace in bulk files

 
Ashwin_4
Frequent Advisor

Date search/replace in bulk files

Hi,
I have 1000 .rtf file, is there any way to search & replace the date in all the files.
I want to chane 10/07/2006 to 31/07/2006.

Thanks in adv
5 REPLIES 5
Victor Fridyev
Honored Contributor

Re: Date search/replace in bulk files

find . -name "*.rtf"| while read F; do
cat $F|sed 's?10/07/2006?31/07/2006?g > /tmp/tempfile
mv /tmp/tempfile $F
done

HTH
Entities are not to be multiplied beyond necessity - RTFM
Peter Nikitka
Honored Contributor

Re: Date search/replace in bulk files

Hi,

I would add some error checking to Victor's response and drop the 'cat':

find . -name "*.rtf"| while read F; do
sed 's?10/07/2006?31/07/2006?g $F > /tmp/tempfile
ret=$?
if [ $ret -eq 0 ]
then
mv /tmp/tempfile $F
ret=$?
fi
if [ $ret -ne 0 ]
then print -u2 ERROR: modification of $F failed
fi
done

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Arturo Galbiati
Esteemed Contributor

Re: Date search/replace in bulk files

Hi,

perl -pe 's@10/07/2006@31/07/2006@' -i *.rtf

HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: Date search/replace in bulk files

Hi,
if you want to save the input files as well:

perl -i.old '-pe s@10/07/2006@31/07/2006@' *.rtf

HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: Date search/replace in bulk files

Hi Ashwin,
please, find a bit of time to assign points people reply you, trying to help.
It's very poor time consuming but very appreciated.

Rgds,
Art