I want to build a script

I have this script

sed -e '$q' -e 's/I/D/g' <inputfile> outfile

which replaces I by D...

I have to run this script in 90 files which their filename starts with CD*. I want to call all these files and execute this command once.
Or schedule it to be executed at 1600hrs every day.

I want to output to the same i.e I'm modifying these file so input file has to have the same file as the output.

thanx forwarded

you can do this

#!bin/sh
for file in `ls CD*`
do
sed -e 's/I/D/g' < $file > $file.out
mv $file.out $file
done

If you want to run it at a specific time, use the cron command there have been plenty of posts on this site about it already.

Just curious what your $q is doing? From the syntax it looks like another sed command....just something I learnt the other day...

He actually doesn't want to change the last line. 'q' is a command that makes sed quit. '$' addresses the last line. So when the last line is encountered, sed exits so that second command never runs. See this thread.

Ah, very clever....context does help.

txs a lot...its working..

I want build a script which will alert me by outlook mail about backup status

The -i option in Perl will edit the specified file "in place", so you don't have to mess with moving files around.

% echo "eat food" >> test.txt
% echo "eat more food" >> test2.txt
% perl -pi -e 's/food/pie/g' *
% cat test.txt
eat pie
% cat test2.txt
eat more pie

-i takes an optional argument. If specified, a backup will be saved with the argument as the file's extension.

% perl -pi'.bak' -e 's/pie/chicken/g' *
% ls
test.txt test.txt.bak test2.txt test2.txt.bak
% cat test.txt
eat chicken
% cat test.txt.bak
eat pie

that looks logical :slight_smile: