Difference between revisions of "Sed"
Jump to navigation
Jump to search
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
grep -rl oldtext . | xargs sed -i 's/oldtext/newtext/g' | grep -rl oldtext . | xargs sed -i 's/oldtext/newtext/g' | ||
| + | |||
| + | |||
| + | find . -type f -name "*.txt" -exec sed -i 's/old_text/new_text/g' {} + | ||
| + | |||
| + | find . -type f -name "*.txt" -exec sed -i '' 's/old_text/new_text/g' {} + | ||
| + | |||
| + | find . -type f -name "*.txt" -print0 | xargs -0 sed -i 's/old_text/new_text/g'v | ||
| + | |||
| + | ## Linux | ||
| + | |||
| + | grep -rlZ --exclude-dir='.git' 'oldtext' . | xargs -0 sed -i 's/oldtext/newtext/g' | ||
| + | |||
| + | |||
| + | ## Macos/freebsd | ||
| + | grep -rl --null --exclude-dir='.git' 'oldtext' . | xargs -0 sed -i '' 's/oldtext/newtext/g' | ||
Latest revision as of 20:07, 3 June 2026
https://opensource.com/article/20/12/sed
grep -rl oldtext . | xargs sed -i 's/oldtext/newtext/g'
find . -type f -name "*.txt" -exec sed -i 's/old_text/new_text/g' {} +
find . -type f -name "*.txt" -exec sed -i 's/old_text/new_text/g' {} +
find . -type f -name "*.txt" -print0 | xargs -0 sed -i 's/old_text/new_text/g'v
Linux
grep -rlZ --exclude-dir='.git' 'oldtext' . | xargs -0 sed -i 's/oldtext/newtext/g'
Macos/freebsd
grep -rl --null --exclude-dir='.git' 'oldtext' . | xargs -0 sed -i 's/oldtext/newtext/g'