Reputation: 81
I have space separated file which contain string as well as numbers. I wanted to only numbers with 2.
So far i was doing
!awk '{for(i=1;i<=NF;i++) $i ~/[^0-9]+/ $i=$i*2; print $0}'
I know my print $0
statement is at wrong place but i don't know correct way.
Can someone help here ?
Upvotes: 0
Views: 167
Reputation: 37424
Another, but using ternary operator:
$ awk '{ for(i=1; i<=NF; i++) (j=$i*2 ? j : $i) } 1' file
Upvotes: 0
Reputation: 67507
multiply all the numbers by 2
$ awk '{for(i=1;i<=NF;i++) if($i+0==$i) $i*=2}1'
Upvotes: 1