Skip to main content
added 96 characters in body
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

With grep and cut. Use grep -o to take only the matched data, look for the requested field and value. Feed that to cut, using = as a field seperator, and take the second field:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed. Look for the requested field/value pair, use () and \1 to extract the matching subpattern:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM

With awk. Set the field separator and record separator to = and , respectively. For the record with the matching pattern, print the second field (i. e. the value):

$ awk 'BEGIN { FS="="; RS=","; } $1 ~ /MIC/ { print $2 }' input
XAIM

With grep and cut:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM

With awk:

$ awk 'BEGIN { FS="="; RS=","; } $1 ~ /MIC/ { print $2 }' input
XAIM

With grep and cut. Use grep -o to take only the matched data, look for the requested field and value. Feed that to cut, using = as a field seperator, and take the second field:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed. Look for the requested field/value pair, use () and \1 to extract the matching subpattern:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM

With awk. Set the field separator and record separator to = and , respectively. For the record with the matching pattern, print the second field (i. e. the value):

$ awk 'BEGIN { FS="="; RS=","; } $1 ~ /MIC/ { print $2 }' input
XAIM
added 96 characters in body
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

With grep and cut:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM

With awk:

$ awk 'BEGIN { FS="="; RS=","; } $1 ~ /MIC/ { print $2 }' input
XAIM

With grep and cut:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM

With grep and cut:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM

With awk:

$ awk 'BEGIN { FS="="; RS=","; } $1 ~ /MIC/ { print $2 }' input
XAIM
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

With grep and cut:

$ grep -o 'MIC=[^,]*' input | cut -d= -f2
XAIM

With sed:

$ sed -nE 's/^.*MIC=([^,]+).*$/\1/;p' input
XAIM
# or, alternatively,
$ sed -n 's/^.*MIC=\([^,]*\).*$/\1/;p' input
XAIM