Hello
I have an output that has a string between quotes and another between square brackets on the same line. I need to extract these 2 strings Example line
Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SN[VD073AV1443BVW00083]L2
Output should look like
nrst3a VD073AV1443BVW00083
I was trying with sed and I can get the quotes but how do I also add the the output for the square brackets on the same sed command.
Thanks for your help
sed -n 's/.*"\([^"]*\)".*\[\([^]]*\)\].*/\1 \2/p'
perl -ne 'print if s/.*"(.*?)".*\[(.*?)\].*/$1 $2/'
bombcan:
Hello
I have an output that has a string between quotes and another between square brackets on the same line. I need to extract these 2 strings Example line
Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SN[VD073AV1443BVW00083]L2
Output should look like
nrst3a VD073AV1443BVW00083
I was trying with sed and I can get the quotes but how do I also add the the output for the square brackets on the same sed command.
Thanks for your help
If you have the output in a variable, you don't need any external command:
output='Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SN[VD073AV1443BVW00083]L2'
IFS=\" read a s1 b <<< "$output"
IFS=\[\] read a s2 b <<< "$output"
echo "$s1 $s2"
This uses bash; in other shells you can do the same with a "here document".
2 Likes
Thank-You cfajohnson & MadeInGermany for your time and these useful posts. They all work great.