[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: config files substitution with awk
From: |
Paolo Bonzini |
Subject: |
Re: config files substitution with awk |
Date: |
Tue, 21 Nov 2006 09:49:56 +0100 |
User-agent: |
Thunderbird 1.5.0.8 (Macintosh/20061025) |
+/@[a-zA-Z_][a-zA-Z_0-9]*@/ {
+ nfields = split($ 0, field, "@")
+ for (i = 1; i <= nfields; i++) {
> + key = field[i]
The space after $ is useless. Furthermore, this is wrong in cases like
address@hidden@address@hidden@.
Rather, you need
nfields = split($0, field, "@")
for (i = 3; i <= nfields; ) {
key = field[i-1]
if (key ~ /[^a-zA-Z_0-9]/)
i++;
else
i += 2;
if (key in S)
sub("@" key "@", S[key])
else if (key in F) {
while ((getline aline < F[key]) > 0)
print(aline)
close(F[key])
next
}
A smaller script to show the idea is this:
awk '{
nfields = split ($0, field, "@");
for (i = 3; i <= nfields; ) {
key = field[i-1];
if (key ~ /[^a-zA-Z_0-9]/) i++; else { print ">> " key;i+=2; }
}
}'
with testcases such as
address@hidden@address@hidden
>> bar
address@hidden@@address@hidden
>> bar
>> cde
address@hidden@@address@hidden@
>> bar
>> cde
address@hidden @address@hidden
>> cde
address@hidden @address@hidden@
>> cde
address@hidden @cde@@ghi@
>> cde
>> ghi
Paolo
- config files substitution with awk, Ralf Wildenhues, 2006/11/19
- Re: config files substitution with awk, Paul Eggert, 2006/11/20
- Re: config files substitution with awk, Ralf Wildenhues, 2006/11/20
- Re: config files substitution with awk,
Paolo Bonzini <=
- Re: config files substitution with awk, Ralf Wildenhues, 2006/11/21
- Re: config files substitution with awk, Paul Eggert, 2006/11/21
- Re: config files substitution with awk, Paul Eggert, 2006/11/21
- Re: config files substitution with awk, Ralf Wildenhues, 2006/11/21
- Message not available
- Re: config files substitution with awk, Paul Eggert, 2006/11/21
- Re: config files substitution with awk, Ralf Wildenhues, 2006/11/24
- Re: config files substitution with awk, Paul Eggert, 2006/11/26
- Re: config files substitution with awk, Ralf Wildenhues, 2006/11/27
- Re: config files substitution with awk, Ralf Wildenhues, 2006/11/28
- Re: config files substitution with awk, Paul Eggert, 2006/11/27