Pergunta

I have to extract a particular character from a string.I am able to do a grep to the whole string but I am not sure how to extract a particular character from the string.Below is my grep code.

1.rpm -qa|grep -i tog-pegasus.2.12.1 //Will give output "tog-pegasus-2.12.1-16.el7.x86_64" 2.From the above output extract 2.12.x that is x from the above output which in this case is 1.

I have used substr but couldnt get the correct one.Kindly help.Thanks.

Foi útil?

Solução

You could use cut:

echo "tog-pegasus-2.12.1-16.el7.x86_64" | cut -d . -f 3 | cut -d - -f 1

This takes the third field, considering that . is the field delimiters, so you get the micro version including the -patchlevel; then it takes the first field, considering that - is the field delimiter, and then you are left with the micro version only.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top