2

I'm trying to get Atom version in bash. Thid regex is working, but I need a substring from string, which giving grep. How can I get version from this string?

<span class="version">1.34.0</span>

curl https://atom.io/ | grep 'class="version"' | grep '[0-9]\+.[0-9]\+.[0-9]\+'
2
  • Possible duplicate of Extract substring in Bash Commented Feb 8, 2019 at 21:14
  • Note if you have Gnu grep you can use the -P option for perl-style regex's and the -o option to print only what matches the pattern. Try this as your last command in the pipeline:grep -oP "\d+\.\d+\.\d+" Oh and notice escaping the dot for a literal dot, otherwise it means any character. Commented Feb 8, 2019 at 22:14

2 Answers 2

2

with awk

$ curl ... | awk -F'[<>]' '/class="version"/{print $3; exit}'
Sign up to request clarification or add additional context in comments.

Comments

0

You can achieve this by using the cut command and adding your respective delimiters; in your case this would be the > and < tags encapsulating the version.

Input:

curl -s https://atom.io/ \
| grep 'class="version"' \
| grep '[0-9]\+.[0-9]\+.[0-9]\+' \
| cut -d '>' -f2 \
| cut -d '<' -f1

Output:

1.34.0

*added the curl -s flag to make output silent, personal choice

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.