Question about using SED?

zfrawg

New Member
Joined
Feb 15, 2022
Messages
2
Reaction score
2
Credits
20
I have a command in the Microsoft Azure cli that produces comma separated output that looks something like this:

Bash:
/subscriptions/test-subscription/resourceGroups/test-resourcegroup/providers/Microsoft.Web/sites/TEST-NAME/providers/Microsoft.Insights/metrics/CpuTime,test-resourcegroup,29.75

In the first value before the comma I want to remove everything before and after TEST-NAME (including the forward slashes) so that the output becomes this:

Bash:
TEST-NAME,test-resourcegroup,29.75

I've played around with SED but can't quite get the output I want.
 


I believe this would be better suited for awk or cut.
I won't give you the whole answer, but start with something like...

cat test | cut -f9,13-15 -d/

try man cut for more info.
 
Thanks for the pointer, after going through cut I actually ended up with a good solution using awk (very handy as well) since I had two delimiters (/ and ,)

This ended up doing the trick:

awk -F'[/,]' '{print $9","$14","$15}'
 
Moving this to Command Line.

Welcome @zfrawg

Chris Turner
wizardfromoz
 


Top