OT: sed/awk pointers needed
Craig Treleaven
ctreleaven at macports.org
Tue Sep 30 19:15:59 PDT 2014
At 2:27 PM -0400 9/30/14, Lawrence Velázquez wrote:
>On Sep 30, 2014, at 12:00 PM, Brandon Allbery <allbery.b at gmail.com> wrote:
> > On Tue, Sep 30, 2014 at 11:44 AM, Craig
>Treleaven <ctreleaven at macports.org> wrote:
> >> I have only rudimentary acquaintance with
>sed and less with awk. I'd like to learn more
>and this seemed like an opportunity to do so.
>[...]
> >
> > Very, very painfully. I think I could do it,
>with a LOT of fiddling, but would very much
>prefer to use a more appropriate tool. awk is
>somewhat better, but I'd reach for
>perl/python/ruby first.
>
>[vq's sed version deleted ...]
As I said, it was a learning exercise and I've
got a working version with gawk. (Awk lacks the
sub()/gsub() string functions.)
My version is:
---------cut from here-------
# identify port name lines by the phrase " has the variants"
/ has the variants/ {
portname = $1
next
}
# deal with the default variant lines, they start with [+]
# (which is a crazy string to match with a regex)
# note that the regex in the pattern match and the sub() function are
# (must be) wildly different!
/^\[+./ {
sub("\\[\\+.", " ")
print portname ", " $1 ", " "Default"
next
}
# All the other variant lines start with 3 spaces, followed by a lower case
# variant name
/^ [a-z]/ {
print portname ", " $1 ", " "N"
next
}
-------------to here------------
And it works as follows:
$ port variants php53-mysql php54-mysql |grep -v
conflicts |grep -e mariadb -e mysql -e percona |
cut -d : -f 1 | gawk -f rejig.awk -
php53-mysql, mariadb, N
php53-mysql, mysql4, N
php53-mysql, mysql5, N
php53-mysql, mysql51, N
php53-mysql, mysql55, N
php53-mysql, mysql56, N
php53-mysql, mysqlnd, Default
php53-mysql, percona, N
php54-mysql, mariadb, N
php54-mysql, mysql4, N
php54-mysql, mysql5, N
php54-mysql, mysql51, N
php54-mysql, mysql55, N
php54-mysql, mysql56, N
php54-mysql, mysqlnd, Default
php54-mysql, percona, N
Now to see if I can actually run this against the
89 ports that appear to have mysql-related
variants...
Craig
More information about the macports-dev
mailing list