0

I have a file "test.htm" with the follwoing content

<html>

<head></head>

<body>site-is-down</body>

</html>

I am trying to make it "site-is-up" if it has text "site-is-down". When I execute the script its showing correct output ,but its not replacing anything in the file

 #!/bin/ksh
if grep "site-is-down" test.htm; then
 sed -e "s/down/up/g" test.htm
else
 echo "Site is already up"
fi

2 Answers 2

1

Change this line:

sed -e "s/down/up/g" test.htm

To this:

sed -i -e "s/down/up/g" test.htm

The -i flag means to edit the file "in-place" rather than to write the replacements to standard output.

Sign up to request clarification or add additional context in comments.

Comments

0

To replace every occurrence of a certain word / string in a ton of files spanning multiple directories, and this is the quickest way I've found to do it. It uses grep to search for a certain word and if it find its it runs sed to replace the strings you want.

grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.