Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to write a script that basically works like Microsoft words find>replace function. It first asks for two inputs from the user. First one for strings to be found and the second one for strings to replace the old ones. Even though this is pretty straight forward, I also want to count the number of things to be replaced and echo the user to confirms these specific number of replacements. How can I do that? So far I have this as the search>replace function:

for file in find -name '*.sdf.new';
do
grep "$search" $file &> /dev/null
sed -i "s/$search/$replace/" $file
done

share

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.