user3798565
user3798565

Reputation: 87

awk print sums of every line, but how to exclude all numbers left from a character

I am using

awk '{s=0; for (i=1; i<=NF; i++) s=s+$i; print s}'   

that prints the sums of the fields of every line. How can I avoid that numbers that are left from the character § are included?
Numbers between § and § are excluded anyway

hrur ueueu 5 ue eeuhe 17 jej 8 kejhfj  
jehe 7 hhhd 5  §ir5uj§ irur 17 jjjhr 8  
plkkwej 8 §h8sq§ oaiwhe 77 jjwgd 33

result:

30  
25  
110

Upvotes: 0

Views: 41

Answers (1)

Barmar
Barmar

Reputation: 781761

Before you loop over the fields, remove everything left of §:

awk '{s = 0; sub(".*§", ""); for (i=1; i<=NF; i++) s=s+$i; print s}'

Upvotes: 3

Related Questions