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.
 


dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
1,388
Reaction score
1,015
Credits
8,525
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.
 
OP
Z

zfrawg

New Member
Joined
Feb 15, 2022
Messages
2
Reaction score
2
Credits
20
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}'
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
7,202
Reaction score
6,107
Credits
24,168
Moving this to Command Line.

Welcome @zfrawg

Chris Turner
wizardfromoz
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top