Skip to content

Instantly share code, notes, and snippets.

@khaliqgant
Last active July 14, 2023 17:57
Show Gist options
  • Save khaliqgant/215b38d3e909b29ac6d2c2920a762832 to your computer and use it in GitHub Desktop.
Save khaliqgant/215b38d3e909b29ac6d2c2920a762832 to your computer and use it in GitHub Desktop.
[Sed Replace In File] Replace Contents In A File #sed #cli
# mac
sed -i '' 's/hello/bonjour' greetings.txt
sed -i '' 's|{{ DB_SHARED_BUFFERS }}|'"$DB_SHARED_BUFFERS"'|g' ./postgres/postgresql.conf
# linux
sed -i 's/hello/bonjour' greetings.txt
sed -i 's|{{ DB_SHARED_BUFFERS }}|'"$DB_SHARED_BUFFERS"'|g' postgres/postgresql.conf
find . -type f -name "*.ts" -print0 | xargs -0 sed -i '' -e 's/[..\/]*shared/@shared/g' && find . -type f -name "*.ts" -print0 | xargs -0 sed -i '' -e "s/@shared'/@shared\/index'/g"
find . -type f -name "*.ts" -print0 | xargs -0 sed -i '' -e 's/activity\.service/activity\/activity\.service/g'
//dont create a .back file
//source http://robots.thoughtbot.com/sed-102-replace-in-place
sed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html
good source: http://www.grymoire.com/Unix/Sed.html#uh-0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment