RogerRab2020 :
So I'm using lsof in combination with jq to convert to json. The original output example:
[
"blah",
"1234",
"yoda",
"561u",
"IPv4",
"297229000",
"0t0",
"TCP",
"15.60.74.17:1511",
"(LISTEN)"
]
]
When using this with sed as:
sed -e "s/(//" -e "s/)//" | sed 's/.*:\([0-9]\+\).*/"\1",/g'
The output comes out as:
[
"blah",
"1234",
"yoda",
"561u",
"IPv4",
"297229000",
"0t0",
"TCP",
"1511",
"LISTEN"
]
]
Notice the space is not kept for "1511" not sure what i'm missing, i'm sure something silly, anyone know what i'm missing here?
dstromberg :
You could use a register, but it's easier to just match less:
echo ' "15.60.74.17:1511",' | sed -e "s/(//" -e "s/)//" -e 's/[0-9\.]*:\([0-9]\+\).*/\1",/g'
BTW, you don't need 2 sed's - just one with two -e's.