The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music.
Hey Augusto. Now that I look at one-liner #8, it looks pretty ridiculous. But I didn't write it.
If I wrote it, here is how it would look:
awk '{ print ++a, $0 }'
At every line increment variable a, and output it together with the line itself.
The explanation of the original one liner is this:
Every line gets read in variable $0. The one-liner modifies this $0. It appends the contents of variable 'a' to the beginning of $0. But before appending 'a' it gets incremented by one by ++ unary operator.
Hi
if code goes like as awk '{ print ++a, $0 }', line numbering included blank lined. But code goes awk 'NF {$0=++a ": " $0}; {print}' that will be add line number to non-blank line.
NF {$0=++a ": " $0} = There must have one field at lease to increase number to var "a" else no action or not take as record for blank line, same time $0 (whole NR ) will become as [var a : ORG_LINE] then print again with all (whole line which newly create include var a value) by print statement after ; .
Correction : ---
if code goes like as awk '{ print ++a, $0 }', line numbering included blank lined. But code goes awk 'NF {$0=++a ": " $0}; {print}' that will be add line number only to non-blank line. Blank will not get line number.
NF {$0=++a ": " $0} = There must have one field at lease to increase number to var "a" else no action or not take as record for blank line, same time $0 (whole NR ) will become as [var a : ORG_LINE] then print again with all (whole line which newly create include var a value) by print statement after ; .
I am being sponsored by Syntress since 2007! They bought me an amazing dedicated server to run catonmat on. If you're looking web services in Chicago area, I highly recommend the Syntress guys!
Hey Augusto. Now that I look at one-liner #8, it looks pretty ridiculous. But I didn't write it.
If I wrote it, here is how it would look:
awk '{ print ++a, $0 }'At every line increment variable a, and output it together with the line itself.
The explanation of the original one liner is this:
Every line gets read in variable $0. The one-liner modifies this $0. It appends the contents of variable 'a' to the beginning of $0. But before appending 'a' it gets incremented by one by ++ unary operator.
Comment Responses
Hi
if code goes like as awk '{ print ++a, $0 }', line numbering included blank lined. But code goes awk 'NF {$0=++a ": " $0}; {print}' that will be add line number to non-blank line.
NF {$0=++a ": " $0} = There must have one field at lease to increase number to var "a" else no action or not take as record for blank line, same time $0 (whole NR ) will become as [var a : ORG_LINE] then print again with all (whole line which newly create include var a value) by print statement after ; .
Correction : ---
if code goes like as awk '{ print ++a, $0 }', line numbering included blank lined. But code goes awk 'NF {$0=++a ": " $0}; {print}' that will be add line number only to non-blank line. Blank will not get line number.
NF {$0=++a ": " $0} = There must have one field at lease to increase number to var "a" else no action or not take as record for blank line, same time $0 (whole NR ) will become as [var a : ORG_LINE] then print again with all (whole line which newly create include var a value) by print statement after ; .
Reply To This Comment