Created
October 7, 2011 15:04
-
-
Save colinux/1270468 to your computer and use it in GitHub Desktop.
awk sous linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool :)