Skip to content

Instantly share code, notes, and snippets.

@colinux
Created October 7, 2011 15:04
Show Gist options
  • Save colinux/1270468 to your computer and use it in GitHub Desktop.
Save colinux/1270468 to your computer and use it in GitHub Desktop.
awk sous linux
$ cat gemspec
WARNING: no homepage specified
Successfully built RubyGem
Name: project
Version: 2.7.5
File: project-2.7.5.gem
# On veut récupérer "2.7.5" et "project-2.7.5.gem":
# -F": " : fixe ": " comme séparateur de champ
# et on ne récupère que les champs qui contiennent des nombres
$ cat gemspec | awk -F": " '{ if ($NF ~ /[0-9]+/) { print $NF; } }'
2.7.5
project-2.7.5.gem
# On ne veut que le numéro de version pour l'assigner dans une variable: on adapte juste la regex
$ V=`cat gemspec | awk -F": " '{ if ($NF ~ /^[0-9\.]+$/) { print $NF; } }'`
$ echo $V
2.7.5
@colinux
Copy link
Author

colinux commented Oct 9, 2011

cool :)

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