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
  • 2
    Show your desired input and output. Be specific about what you are changing to what.
    – DopeGhoti
    Jan 5, 2016 at 23:23
  • Can you please provide an example of the expected output from your sed?
    – Munir
    Jan 5, 2016 at 23:23

1 Answer 1

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" {} \;
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .