csta
csta

Reputation: 2553

setting a bash variable in awk

I have

grep 5980 list.txt > temp; awk '{ print $4}' temp

but instead of just printing the results I would like to set it to an environment variable.

I'm kind of new to bash and awk so an explanation would also be much appreciated.

Upvotes: 3

Views: 3154

Answers (2)

Vijay
Vijay

Reputation: 67301

If you dont need to save the output in temp,you can use the below command:

export variable=$(awk '/5980/{print $4}' list.txt) 

Upvotes: 3

Mu Qiao
Mu Qiao

Reputation: 7107

Use command substitution

export variable=$(grep 5980 list.txt > temp; awk '{ print $4}' temp)

Upvotes: 4

Related Questions