Number Output Lines

Problem

You want to number each line of output.



Solution

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.



Example



echo "testingntestingn123" | perl -e 'while(<>) {
chomp();
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



Reference

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



Previous Post

Next Post

Leave a Reply

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