0

Here is my command:

aws logs describe-metric-filters --log-group-name mahi | jq '.metricFilters[].metricTransformations' | grep "metricName"

output:

"metricName": "APIMetric",

"metricNamespace": "APINamespace",

From the above command i need only the metricName where it is grepping both the words which starts with metricName.

1 Answer 1

1

Easiest way is to tell grep it needs to find the quotation marks too. You can avoid any escaping shenanigans by wrapping the search text in single quote marks:

aws logs describe-metric-filters --log-group-name mahi | jq '.metricFilters[].metricTransformations' | grep '"metricName"'
5
  • Yeah cool! its working for me
    – allada01
    Jul 22, 2020 at 5:21
  • From the same command how can i grep the value of the metricName which is in the format "metricName": "APIMetric",
    – allada01
    Jul 22, 2020 at 5:24
  • 3
    @allada01 if that's all you're after, you can probably just use jq to get the value. can you not just do jq '.metricFilters[].metricTransformations.metricName' and skip the grep? Hard to be certain without seeing the JSON structure, but I don't see why it wouldn't work.
    – Dan Scally
    Jul 22, 2020 at 5:33
  • yeah i have tried with the same method but it didnt work, aws logs describe-metric-filters --log-group-name mahi | jq '.metricFilters[].metricTrandformations.metricName' where the ouptut it is showing as null
    – allada01
    Jul 22, 2020 at 5:44
  • @allada01 can you show some of the json? removing the Values is fine if you want to do that, as long as you leave something to indicate what type the value was (I.E. string, array or whatever)
    – Dan Scally
    Jul 22, 2020 at 5:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .