Help for this page

Select Code to Download


  1. or download this
    # style: what i like (my latest first two attempts)
    perl -e"printf('%4s: %s',++$a,$_)while(<>)" file
    ...
    # style: [craft] (craft doesn't handle 3digits well)
    # you can always change the 2 into 3 to handle 3 digit nums
    perl -pe"printf'%-2s: ',++$a" file
    
  2. or download this
    ########## my favorite (never forget perlvar, thanks davorg)
    perl -pe "printf'%4u: ',$." file
    ...
    # or to prevent 'overflow'
    
    perl -pe "printf'%4.4s: ',$." file