If you know the occurence of : character in your input, you could do something like this.
echo " <j.2:Taxo_Version rdf:resource="refmat:taxonomies-8.2.0"/>" |
awk -F\: '{print $4}' | sed 's/..$//'
The awk
command prints the 4th string after the : delimiter and the sed
command is used to remove the last 2 characters to get the desired output.
However, if this method works or not depends on your input as terdon points out in his comments.
EDIT
The final pipe to sed
could very well be avoided if we use the solution as suggested by jasonwryan in the comments. So, the command would effectively be rephrased as,
echo " <j.2:Taxo_Version rdf:resource="refmat:taxonomies-8.2.0"/>" |
awk -F: '{sub(/\/>/,""); print $4}'
Another solution just using cut and rev can be framed as,
echo " <j.2:Taxo_Version rdf:resource="refmat:taxonomies-8.2.0"/>" |
cut -d ':' -f4 | rev | cut -c 3- | rev
Again the specifying of delimiter is dependent on the input file and from the example you have provided the characters that I need to extract occur after the 4th position of the delimiter. I use cut
to extract the substring after this 4th delimiter and use good old rev
technique to reverse the string and remove the last 3 characters and again apply rev
on it to get the actual string.