Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / perl_regex_examples.sh
Last active December 12, 2018 02:24
Perl Bash/Shell RegEx Examples
# example perl one line replacing contents in a file in place
perl -pi -e 's/something_to_match/replaced_with/' ./my_path/to_file.txt
# Additional regex modifiers got global multi-line and case insensitive
perl -pi -e 's/something_to_match/replaced_with/gmi' ./my_path/to_file.txt
# Using different delimiters for the regex, in this case using a # instead of the tranditional /
perl -pi -e 's#something_to_match#replaced_with#' ./my_path/to_file.txt
# If you don't want to modify a file in place you can split things up a bit