Question : Linux Grep and awk command output in proper format

I have simple ASCII files, which have following data:

name: "Mobile Operator 1"
common.enabled: 1
common.id: 10868
common.net_tech: 0
common.e164_prefixes: ""
common.e212_prefixes: "010868*"
common.imsi_param1: ""
common.imsi_param2: ""
common.imsi_param3: ""
common.imsi_param4: ""
common.gsma_oc_compliant: 0
common.src_nw_resolution: 0
common.op_restriction: 0
op_gw_tx.self_spons_routes.000.route: "My ss7 Route"
op_gw_tx.self_spons_routes.000.is_default: 1
op_gw_tx.self_spons_routes.000.route_availability: 0
op_gw_tx.self_spons_routes.000.x_ops: ""
op_gw_tx.self_spons_routes.000.x_dcs: ""
op_gw_tx.priority_sri: 0
op_gw_tx.priority_threshold: 0
op_gw_tx.rs_mode: 2
op_gw_tx.denied_routes: ""
op_gw_rx.gw_routes.000.route: "MY SMPP Gw"
op_gw_rx.gw_routes.000.is_default: 1
op_gw_rx.gw_routes.000.route_availability: 0

I would like to read above files(so many files for many operators) and print lin csv format:

Mobile Operator 1,10868,MY SMPP Gw,some other info also.

Thanx in adavance



Answer : Linux Grep and awk command output in proper format

In the awk always use $2, don't increment to $3....

To remove the ", run tr -d '"'

1:
2:
3:
4:
#!/bin/sh
for file in `ls test`; do
   echo "`grep '^name:' $file | cut -d':' -f2`,`grep '^common.id:'  $file | cut -d':' -f2`,`grep '^op_gw_rx.gw_routes.000.route:' $file | cut -d':' -f2`,`grep '^op_gw_rx.gw_routes.000.route:' $file | cut -d':' -f2`" | tr -d '"'
done
Open in New Window Select All
Random Solutions  
 
programming4us programming4us