GNU AWK also recently added a CSV mode, but it explicitly only works for comma-separated values, and not for whitespace-separated values like the Apache HTTPD logs

Follow

@aescling @monorail @vaporeon_ the extended POSIX square bracket shit pisses me off for no reason

@wallhackio @aescling @monorail @vaporeon_ are whitespace separated values not the default for awk????

@Lady @wallhackio @aescling @monorail Did you read the thread? Yes, values are separated by whitespace in AWK, but it doesn't handle quoting. "foo bar" would be treated as two fields "foo and bar". That's the whole problem.

@vaporeon_ @wallhackio @aescling @monorail ah yes, i see now

you can solve this in sed but it isn’t pretty

@Lady @wallhackio @aescling @monorail Is it similar to the solution that I found for AWK? glaceon.social/@vaporeon_/1170

(Sorry for reacting with "did you even read the thread?" when it's actually not in the same thread... Link to the actual thread I meant is above. My fault.)

@vaporeon_ @wallhackio @aescling @monorail i was thinking something like this (untested; may not work)

x;s/.*//;x

:outside
/^[^ ]*"/{
s/"/"\n/
H
x;s/[^\n]*$//;x
s/.*\n//
b inside
}
/ /{
s/ /,\n/
H
x;s/[^\n]*$//;x
s/.*\n//
b outside
}
b done

:inside
/^[^ ]*"/{
s/"/"\n/
H
x;s/[^\n]*$//;x
s/.*\n//
b outside
}
/ /{
s/ / \n/
H
x;s/[^\n]*$//;x
s/.*\n//
b inside
}
b done

:done
H
x
s/\n//

(note that this does not handle unquoted commas which may need to be quoted)

(can you solve this with a single regex? maybe??? but i was thinking of just writing a parser)

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.