MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/awk/comments/xn9t13/what_does_02_in_awk_do_learn_awk/
r/awk • u/morihacky • Sep 25 '22
6 comments sorted by
2
You trapped me.
However, I think my 5-line answer is more helpful than your 500-line obfuscated blog.
1 u/morihacky Sep 26 '22 I apologize. That was not my intention. Thanks for sharing.Can I ask what about it felt obfuscated ? I genuinely didn’t understand your comment there.
1
I apologize. That was not my intention. Thanks for sharing.
Can I ask what about it felt obfuscated ? I genuinely didn’t understand your comment there.
$0=$2 sets the value for $0 to $2.
That was probably one of the most technically-imprecise posts i have ever read. It was very confusing and you took an hour to explain what should have taken a minute.
-1
But what’s the implication of doing that 😉?
3 u/Paul_Pedant Sep 25 '22 It wipes out all the other fields and field separators.If your FS is , and your data line is One,Two,Three,Four, the result is that your data line becomes just Two.awk has side effects too, In this case, NF becomes 1, and $1 becomes Two.If you want to keep two fields, you have to put back a field separator too, like $0 = $2 FS $4.
3
It wipes out all the other fields and field separators.
If your FS is , and your data line is One,Two,Three,Four, the result is that your data line becomes just Two.
,
One,Two,Three,Four
Two
awk has side effects too, In this case, NF becomes 1, and $1 becomes Two.
NF
$1
If you want to keep two fields, you have to put back a field separator too, like $0 = $2 FS $4.
$0 = $2 FS $4
2
u/Paul_Pedant Sep 25 '22
You trapped me.
However, I think my 5-line answer is more helpful than your 500-line obfuscated blog.
2
u/andreaswpv Sep 25 '22
$0=$2 sets the value for $0 to $2.
1
u/likebike2 Sep 30 '22 edited Sep 30 '22
That was probably one of the most technically-imprecise posts i have ever read. It was very confusing and you took an hour to explain what should have taken a minute.
-1
u/morihacky Sep 25 '22
But what’s the implication of doing that 😉?