Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created November 1, 2017 13:39
Show Gist options
  • Select an option

  • Save tanepiper/e15bf17e45c82af38c6ef6afcbbaa618 to your computer and use it in GitHub Desktop.

Select an option

Save tanepiper/e15bf17e45c82af38c6ef6afcbbaa618 to your computer and use it in GitHub Desktop.
Given a version returned of 1.2.3-beta.0 from the package I only want the "1.2.3" part
# Given a version returned of 1.2.3-beta.0 from the package I only want the "1.2.3" part
grep -m1 version package.json | awk -F: '{ print $2 }' | sed 's/[^0-9.].*//g'
# Running the above command I get an empty output. But if I manually run the result:
echo "1.2.3-beta.0", | sed 's/[^0-9.].*//g'
# I get 1.2.3
@tanepiper
Copy link
Author

Solution found:

grep -m1 version package.json | sed -E 's/.*"(([0-9]+\.?)+).*/\1/'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment