0

From linux Bash can you help me on how to show only the

Monitoringmetric=1.5Count

instead of

Monitoringmetric=1.5Count;1;2
SLePort
  • 15,211
  • 3
  • 34
  • 44
  • `echo "Monitoringmetric=1.5Count;1;2" | cut -f1 -d";"` – Jean-François Fabre Oct 04 '16 at 17:00
  • 1
    You can use bash for this: `s='Monitoringmetric=1.5Count;1;2'; echo "${s%%;*}"` – anubhava Oct 04 '16 at 17:01
  • Thanks Jean and anubhva, both suggestions works like charm can I ask one more on how can I only cut and show only = 1.5 – Apps Tester Oct 04 '16 at 17:10
  • Please don't turn the comment section into a Q-and-A session. If you have an answer, post it as an answer. @AppsTester If you have a follow-up question, post a new question. – chepner Oct 04 '16 at 17:34
  • FInally showed it but seems to be a long command, please advise if there is a way I can shorten this $ echo "Monitoringmetric=1.5Count;1;2" | cut -f2 |sed -e 's/Monitoringmetric=//g' | cut -f1 -d ";" | sed -e 's/Count//g' – Apps Tester Oct 04 '16 at 17:50

3 Answers3

0

FInally showed it but seems to be a long command, please advise if there is a way I can shorten this

$ echo "Monitoringmetric=1.5Count;1;2" | cut -f2 |sed -e 's/Monitoringmetric=//g' | cut -f1 -d ";" | sed -e 's/Count//g'

  • Why are you doing the **cut -f2** that doesn't seem to accomplish anything? What are you trying to extrace from the input? Just **1.5** ? – blackpen Oct 04 '16 at 18:38
0

Since you seem to be interested only capturing the number after the Monitoringmetric=, you can do:

echo "Monitoringmetric=1.5Count;1;2" | sed -n -e 's/^Monitoringmetric=\([0-9.]*\).*/\1/p'
blackpen
  • 2,339
  • 13
  • 15
0

If your string is in a variable, you could also use ${a%%;*}, for example:

a="Monitoringmetric=1.5Count;1;2"
echo ${a%%;*}
Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31