1

i want to replace a string in many files like "Total:*points" using sed. I simply don't know how to use sed with regex. Below is what i got. Thank you in advance!

find ./ -iname "skp-corr-*.txt" -exec sed -i "" "s/(Total: )(.*)(points)/Total: X \/ 31 points/g" {} \;

Example file before: Total: 4 / 22 points

Example file after: Total: x / 30 points

  • 2
    Show your desired input and output. Be specific about what you are changing to what. – DopeGhoti Jan 5 '16 at 23:23
  • Can you please provide an example of the expected output from your sed? – Munir Jan 5 '16 at 23:23
1

sed is already built to use regex.

find ./ -iname "skp-corr-*.txt" -exec sed -i "s@Total:.*points@Total: X / 30 points@g" {} \;

For OS X,

find ./ -iname "skp-corr-*.txt" -exec sed -i "" -e "s@Total:.*points@Total: X / 30 points@g" {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.