I need to escape \n so on output I really get newline or tab
$ perl -p -e 's/e/a/ge'
now I want each e to be substituted with \n
$ perl -p -e 's/e/\n/ge'
but even \n gives me an error.
this was a simplified example. In real script(makefile) I have
substitute := perl -p -e 's/@([^@]+)@/defined $$ENV{$$1} ? $$ENV{$$1} : $$1/ge'
and in target I have such a nice command
$(substitute) $< > $@
and if the input file for perl contains \n
at output I will see it literally... I want to have real newline.
Remove the e
modifier and the substitution will work fine:
perl -p -e 's/e/\n/g' file
From perldoc perlop:
e Evaluate the right side as an expression.
UPD: If you want to preserve it, put the escape sequence in double quotes:
perl -p -e 's/e/"\n"/ge' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With