Introducing how to perform regex replacement on multiline text data/text files with newlines using the Perl programming language from Linux command line Bash, PowerShell, or cmd.
ASUS:/mnt/c/pg$ printf "hoge\nfuga\nfoo" | perl -pe 's/.*fuga//igs'
hoge
ASUS:/mnt/c/pg$ printf "hoge\nfuga\nfoo" | perl -pe 'BEGIN{undef $/;} s/.*fuga//smg'
foo
With Ruby, you can just specify options…
When passing standard input from Bash for multiline replacement, sed won’t work, Python doesn’t seem to work either, so what remains is this Perl and probably Ruby can do it too. Maybe PHP can as well. I used Perl this time, but I think the code could be shorter with Ruby.