3 ms·
For my & others' reference (because I keep having to look it up, just like parent): perl -ne "print $_;" '-n' will run the expression over each line of th
by AceJohnny2 7y ago
For my & others' reference (because I keep having to look it up, just like parent):
perl -ne "print $_;"
'-n' will run the expression over each line of the input. This is the Awk-like mode.
perl -pe "s/foo/bar/"
'-p' will run the expression over each line of input, and print out the (possibly modified) line. This is the Sed-like mode.
Slightly more info available in `man perlrun` or https://perldoc.perl.org/perlrun.html https://perldoc.perl.org/perlrun.html
- hf 7y agoOne particularly mnemonic collection of switches is 'plane': perl -plane 'my $script' which iterates over all files given on the command-line (or stdin) and + (p)rints every processed line back out + deals with (l)ine endings, in and out + (a)utosplits every line into @F I am aware that -n and -p are mutually exclusive, but as -p overrides -n, it's seems simpler to just keep 'plane' in mind and remove the 'p' if necessary.