Number Output Lines


You want to number each line of output.



Again other ways to do this with UNIX, such as grep -vn XXXX filename.

But sure there are times you want the line number, of standard input.



echo "testingntestingn123" | perl -e 'while(<>) {
print($..": ".$_."n");

1: testing
2: testing
3: 123

Or all on one line

echo "testingntestingn123" | perl -ane 'chomp();print($..": ".$_."n");'
1: testing
2: testing
3: 123



[tags]Automatic Numbering, Perl Coding School[/tags]


If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *