Reputation: 625
I have one file which have many fields so I manage to pull partial data that I need using
variable= awk -F "," '{print $2}' filename.txt
and the string that I get is
"client":"c62e-c5a9-4611-91c6-118b4ee"
so now I want to try to change this string to
export client=c62e-c5a9-4611-91c6-118b4ee
when I try with
variable2= awk -F """ '{print $4}' $variable
it does not work as my plan was to pull this string first 62e-c5a9-4611-91c6-118b4ee then after that append export client= inf front of that, but I could not do that way also.
can someone help on this either awk or sed that give me that desired outcome will appreciate it.
thanks
updates: and here is the completed code, based on request I put masked code with sample output I'm looking for.
{"name":"metering","client":"c62e-c5a9-4611-91c6-118b4ee","client_s":"roubhaofga4mm67ncd6","audience":["metering","c68f932e-c5a9-4611-91c6-118b4ef840fe"],"acces_allowed_types":["BEARER"],"grant_types":["CLIENT_CREDENTIALS"],"subject_type":"PUBLIC","access_t":"BEARER","id_t":"UNSIGNED_JWT","resource_":"ACCESS","resource_level":"PUBLIC","token_expiration":3600,"refresh":604800,"scopes":[{"name":"metering","description":"metering"}],"client_method":"CLPOST"}
what I did is
variable= awk -F "," '{print $2}' filename.txt
echo $variable
output that I'm getting is
"client":"c62e-c5a9-4611-91c6-118b4ee"
what I want is
export client=c62e-c5a9-4611-91c6-118b4ee
Upvotes: 1
Views: 72
Reputation: 133528
I could see some space between equal and your command and it is not wrapped within $
too.
var=$(your command)
Since you haven't shown us sample Input so based on what you have shown.
echo "$your_variable" | awk '{gsub("\042","");sub(/:/,"=");print "export",$0}'
Though if you could show us some sample Input and sample expected output more accurately then could have helped more on this.
Upvotes: 1