Command Line Search/Replace
Find files w/find
find . -name vim.html find . -name 'vi*.html'
Search file content w/grep
grep -r '/notes/vim.html' *
Show only the file names:
grep -rl '/notes/vim.html' *
Replace w/sed
Replace on STDIN:
echo "Hello World" |sed 's/Hello/Goodbye/g'
Use alternative regex delimiter:
echo '<a href="/notes/vim.html>...' |sed 's#/notes/vim.html#/notes/vim.html#g'
Replace in file with -i
:
sed -i 's#/notes/vim.html#/notes/vim.html#g' index.html
Bulk replacing in multiple files:
for file in `grep -rl '/projects/notes/vim.html' *`; do sed -i 's#/projects/notes/vim.html#/notes/vim.html#g' $file done