Skip to content

Instantly share code, notes, and snippets.

@hongry18
Last active November 8, 2017 00:42
Show Gist options
  • Save hongry18/7ef6ff7c1a704a4b4383cb47381d89ee to your computer and use it in GitHub Desktop.
Save hongry18/7ef6ff7c1a704a4b4383cb47381d89ee to your computer and use it in GitHub Desktop.
replace regular expression String

Replace Regular Expression

Linux Find exec

find ./ -name '*.ext' -exec sed -i '%s/old/new/g' {} ;

find & xargs

find ./ -name '*.ext' | xargs sed -i '%s/old/new/g'

sed include newline

sed ':a;N;$!ba;s/\n/ /g' file

:a create a label 'a'
N append the next line to the pattern space
$! if not the last line, ba branch (go to) label 'a'
s substitute, /\n/ regex for new line, / / by a space, /g global match (as many times as it can)

vim

:%s/old/new/g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment