mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-17 09:25:32 +00:00
Add to _perl/1line
This commit is contained in:
parent
341ff5636f
commit
59ac157226
@ -44,6 +44,7 @@ perl -lpe '$\ = $. % 10 ? "\t" : "\n"'
|
|||||||
|
|
||||||
# Number all lines in a file
|
# Number all lines in a file
|
||||||
perl -pe '$_ = "$. $_"'
|
perl -pe '$_ = "$. $_"'
|
||||||
|
perl -ne 'print("$. $_")'
|
||||||
|
|
||||||
# Number only non-empty lines in a file
|
# Number only non-empty lines in a file
|
||||||
perl -pe '$_ = ++$a." $_" if /./'
|
perl -pe '$_ = ++$a." $_" if /./'
|
||||||
@ -53,6 +54,8 @@ perl -ne 'print ++$a." $_" if /./'
|
|||||||
|
|
||||||
# Number all lines but print line numbers only non-empty lines
|
# Number all lines but print line numbers only non-empty lines
|
||||||
perl -pe '$_ = "$. $_" if /./'
|
perl -pe '$_ = "$. $_" if /./'
|
||||||
|
perl -pe '$_ = "$. $_" unless /^$/'
|
||||||
|
perl -pe '/^$/ or $_ = "$. $_"'
|
||||||
|
|
||||||
# Number only lines that match a pattern, print others unmodified
|
# Number only lines that match a pattern, print others unmodified
|
||||||
perl -pe '$_ = ++$a." $_" if /regex/'
|
perl -pe '$_ = ++$a." $_" if /regex/'
|
||||||
@ -82,6 +85,7 @@ perl -E 'say~~grep/./,<>'
|
|||||||
|
|
||||||
# Print the number of empty lines in a file
|
# Print the number of empty lines in a file
|
||||||
perl -lne '$a++ if /^$/; END {print $a+0}'
|
perl -lne '$a++ if /^$/; END {print $a+0}'
|
||||||
|
perl -lne '/^$/ && $L++; END{print($L)}'
|
||||||
perl -le 'print scalar(grep{/^$/}<>)'
|
perl -le 'print scalar(grep{/^$/}<>)'
|
||||||
perl -le 'print ~~grep{/^$/}<>'
|
perl -le 'print ~~grep{/^$/}<>'
|
||||||
perl -E 'say~~grep{/^$/}<>'
|
perl -E 'say~~grep{/^$/}<>'
|
||||||
@ -89,6 +93,7 @@ perl -E 'say~~grep{/^$/}<>'
|
|||||||
# Print the number of lines in a file that match a pattern (emulate grep -c)
|
# Print the number of lines in a file that match a pattern (emulate grep -c)
|
||||||
perl -lne '$a++ if /regex/; END {print $a+0}'
|
perl -lne '$a++ if /regex/; END {print $a+0}'
|
||||||
perl -nE '$a++ if /regex/; END {say $a+0}'
|
perl -nE '$a++ if /regex/; END {say $a+0}'
|
||||||
|
perl -lne '/^#/ && $L++; END{print($L)}'
|
||||||
|
|
||||||
#
|
#
|
||||||
# CALCULATIONS
|
# CALCULATIONS
|
||||||
|
Loading…
Reference in New Issue
Block a user