nl [ -i ] line number increment at each line

commandline session

$cat comma.pl
use strict;
use warnings;

for (qw/ 179550 45960 890458 -12345678 1000000000000/) {
  (my $n = $_) =~ s/(d+?)(?=(d{3})+b)/$1,/g;
  print "$nn";
}

$nl comma.pl
     1	use strict;
     2	use warnings;

     3	for (qw/ 179550 45960 890458 -12345678 1000000000000/) {
     4	  (my $n = $_) =~ s/(d+?)(?=(d{3})+b)/$1,/g;
     5	  print "$nn";
     6	}

$nl -i2 comma.pl
     1	use strict;
     3	use warnings;

     5	for (qw/ 179550 45960 890458 -12345678 1000000000000/) {
     7	  (my $n = $_) =~ s/(d+?)(?=(d{3})+b)/$1,/g;
     9	  print "$nn";
    11	}

$nl -i3 comma.pl
     1	use strict;
     4	use warnings;

     7	for (qw/ 179550 45960 890458 -12345678 1000000000000/) {
    10	  (my $n = $_) =~ s/(d+?)(?=(d{3})+b)/$1,/g;
    13	  print "$nn";
    16	}

$

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s