1

how to collect add do existing "b" values next matching?

input:

1:2:3:4:5
6:7:8:9:0
1:3:2:4:5


$ echo -e "1:2:3:4:5\n6:7:8:9:0\n1:3:2:4:5"|awk -F: '$1=="1"{b="line "NR" "$2;print b}'
line 1 2
line 3 3

so finally "b" is set to "line 1 2 line 3 3"

is the something like b=+ in awk?

  • 3
    b = b "some string" ? – Kusalananda Mar 22 '18 at 13:45
  • you are right, ...|awk -F: '$1=="1"{b=b"line "NR" "$2" "}END{print b}' – DonJ Mar 22 '18 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.