Yo tengo esta sentencia en el archivo xxx.txt:
select camp1,camp2,campN from pricing_user.prc_pvp a join ( select werks, matnr, pvp_category_type, max(start_date) as recent_date from pricing_user.prc_pvp where werks = "0006" and pvp_category_type in (1,3) group by 1,2,3 ) b on a.matnr = b.matnr and a.werks = b.werks and a.pvp_category_type=b.pvp_category_type where recent_date = start_date
Si quiero saber cuántos registros me va a dar esa consulta, solo hago:
select count(*) from pricing_user.prc_pvp a join ( select werks, matnr, pvp_category_type, max(start_date) as recent_date from pricing_user.prc_pvp where werks = "0006" and pvp_category_type in (1,3) group by 1,2,3 ) b on a.matnr = b.matnr and a.werks = b.werks and a.pvp_category_type=b.pvp_category_type where recent_date = start_date
Este tipo de tarea lo hago muy repetitivo y quiero automatizarlo, pero para eso, tendría que cambiar todos los campos camp1, camp2,....campN
por count(*)
.
El problema es que no lo logro hacer . Estoy haciendo esto:
sed -i 's/select/select count\(\*\);/g' xxx.txt|sed 's/from/;from/g' |awk -F";" '{print $1 " " $3}'
Pero la salida es:
select count(*) from pricing_user.prc_pvp a join ( select count(*)
y lo que quiero es:
select count(*) from pricing_user.prc_pvp a join ( select werks, matnr, pvp_category_type, max(start_date) as recent_date from pricing_user.prc_pvp where werks = "0006" and pvp_category_type in (1,3) group by 1,2,3 ) b on a.matnr = b.matnr and a.werks = b.werks and a.pvp_category_type=b.pvp_category_type where recent_date = start_date