Reputation: 188
I am looking for assignment of value of variable to another variable in awk.
Below is the example
if (substr($0,1,1) == "4")
{
COUNT_DETAIL_SEG++
SUM_OF_DETAIL_RCDS=$(COUNT_DETAIL_SEG)
print "Sum of detail records is" SUM_OF_DETAIL_RCDS
}
Suppose if 1st character of line comes out to be "4" then i want to increment value of COUNT_DETAIL_SEG
and assign this value to SUM_OF_DETAIL_RCDS
and thereby print it.
But i am unable to retain this value.
Can anyone have any idea about this?
Upvotes: 1
Views: 123
Reputation: 184955
I think instead of
SUM_OF_DETAIL_RCDS=$(COUNT_DETAIL_SEG)
you want :
SUM_OF_DETAIL_RCDS=COUNT_DETAIL_SEG
because in awk, when you put $(INT)
, you refer no the N'th column of the current input line.
Upvotes: 1
Reputation: 16379
Maybe you want to do this at the start of the awk statement. @sputnick is on the right track.
awk -v var="$bash_var" '{ awk code here}'
This will use the awk internal variable var
instead of the shell variable bash_var
.
Upvotes: 0