- 论坛徽章:
- 145
|
回复 1# number321
$ awk -f q.awk FILE
NF=15 before modified
NF=12 after modified
$1 = <1.1.1.1>
$2 = <->
$3 = <->
$4 = <[26/Dec/2015:00:05:43>
$5 = <+0800]>
$6 = <"GET /123/ HTTP/1.1">
$7 = <503>
$8 = <1706>
$9 = <"-">
$10 = <"Googlebot/2.1 (+http://www.google.com/bot.html)">
$11 = <"www.test.com">
$12 = <13920>
$ cat q.awk
function qq( c,n){
c = 0;
for (n = 1; n <= NF; n++) {
if($n~/^"/ && $n~/"$/){
#gsub(/"/,"") # for removed the "
$(++c) = $n
continue
}
if(q == 1){
if($n~/"$/){
#if(sub(/"$/,"",$n)){ # for removed the "
q = 0
}
$c = $c FS $n
continue
}
if($n~/^"/){
#if(sub(/^"/,"",$n)){ # for removed the "
q = 1
$(++c) = $n
continue
}
$(++c) = $n
}
NF = c
}
{
print "NF="NF,"before modified"
qq();
print "NF="NF,"after modified"
for (n = 1; n <= NF; n++) {
printf("$%d = <%s>\n", n, $n)
}
}
|
|