Saturday, November 05, 2016

Cute Perl One Liner

Just remember there's more than one way to do it and I'm not the smartest guy around..

Turn

1
1
1
1
1

into

1
2
3
4
5

That doesn't sound hard. But, what if you have 10 seconds to turn

ssd1
ssd1
ssd1
ssd1
ssd1

into .. well, you know..

Easy : Use NEdit (the best text editor) and select the column of 1's and then pipe through (ALT-r)

perl -p -e 's/./$./;'

Yes, $. (dollar period) means current input line number.

Turn a column of the same number into a sequence of uniformly increasing numbers using perl..

No comments: