Add line number count as C-style comments

awk '{printf("/* %02d */ %s\n", NR,$0)}' inputfile > outputfile
I often find the need to number enumerations and other lists when programming. With this command, create a new file called 'inputfile' with the text you want to number. Paste the contents of 'outputfile' back into your source file and fix the tabbing if necessary. You can also change this to output hex numbering by changing the "%02d" to "%02x". If you need to start at 0 replace "NR" with "NR-1". I adapted this from
Sample Output
/* 01 */ first
/* 02 */ second
/* 03 */ third
/* 04 */ fourth
/* 05 */ fifth
/* 06 */
/* 07 */ seventh

2011-01-04 19:13:55

What Others Think

Through these websites, you will learn how to add line number count as C-style comments. The working of these commands is what causes gout clearly mentioned here. This is the best place that helps you to learn such commands very easily. I am looking here for more updates.
Alyssalauren · 42 weeks and 1 day ago
Excellent you're a good coder I try and it completely work. quordle game
thomasfrank · 4 weeks and 1 day ago
It’s really awesome. I love it. very interesting and meaningful post. I got some very important views in your post which are very good and applicable for me. I just wish that I’ll see your another post very soon. I am waiting for that. fnf mod
istrosin · 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: