unix - Specifying the order of output using awk -


I have a file named testfile, with the following content:

  {"item"   : "[Created on" ogit / / _ ": 1413388512511," \ / environmentType ":" prod "," \ / soxRelevant ":" true "," \ / EnvironmentName ":" dbVertical "}]}  

I used the following awk command to get value for socks revival, environment type and environment name.

  Cat test file | TR -D '' '| {, "FS =",: "; ORS = ","; Awk 'rs =} start "/ soxRelevant / {$ 2 print}; / environmentType / {$ 2 print}; / environmentName / {print $ 2};'  

The output was as follows :

  PROD, true, db vertical,  

Although I want to first socks relevant output, the name of environment after the type of environment, such as awk The command is specified in:

I should be output:

  true, PROD, dbVertical  

How do I do this?

You can push elements into an array , Then print them in the end block:

  awk 'start {RS = ORS = "," FS = ":"} "/ soxRelevant / {a [1] = $ 2 } / EnvironmentType / {print a [2] = $ 2} / environment name {a [3] = $ 2} for END {n = 1; n  

Comments