Skip to content

Instantly share code, notes, and snippets.

@Rodrigora
Last active January 5, 2021 13:02
Show Gist options
  • Save Rodrigora/61a2233dcad0b4c637e44cc2d0596460 to your computer and use it in GitHub Desktop.
Save Rodrigora/61a2233dcad0b4c637e44cc2d0596460 to your computer and use it in GitHub Desktop.
Replace string in files
# finds all files in app folder with .rb extension
# for each file
# capitalizes every "cr" strings preceded by a non-letter and followed by a capital letter
find app -name '*.rb' -exec sed -i '' -- "s/\([^a-zA-Z]\)[Cc][Rr]\([A-Z]\)/\1CR\2/g" {} +
# rename PGIntegrationError -> CRProviderError
find app -name '*.rb' -exec sed -i '' -- "s/PGIntegrationError\CRProviderError/g" {} +
find app spec config lib -name '*.rb' -exec sed -i '' -- "s/pg_integration_error\?\cr_provider_error\?/g" {} +
#shell
find . -name '*.rb' -exec sed -i -- "s/CrLoginStatus/CRProviderSubmission/g" {} +
find . -name '*.rb' -exec sed -i -- "s/cr_provider_submissiones/cr_provider_submissions/g" {} +
find . -name '*.rb' -exec sed -i -- "s/CRProviderSubmissioes/CRProviderSubmissions/g" {} +
CRProviderSubmissiones
cr_login_status
find . -name '*.rb' -exec sed -i -- "s/cr_login_status/cr_provider_submission/g" {} +
# finds all files in app folder starting with cr followed by a capital character
grep -rn "\b[Cc][Rr]\([A-Z]\)" app
grep -rn "\b[\w]?PG[\w]?[Ee]rror" app
# find multiple patterns
cat log/file.log | grep -P '^(?=.*pattern1)(?=.*pattern2)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment