Use FPAT
if your awk
supports, its an awk
s built-in variable to define the regex for fields rather than the delimiters. ITs like a complement to FS
which is also awk
s builtin variable.
Example:
echo 'hey there,ola,"Nice, command",ola' |awk -v FPAT='[^,]+|"[^"]+"' '{print $1}'
hey there
echo 'hey there,ola,"Nice, command",ola' |awk -v FPAT='[^,]+|"[^"]+"' '{print $2}'
ola
echo 'hey there,ola,"Nice, command",ola' |awk -v FPAT='[^,]+|"[^"]+"' '{print $3}'
"Nice, command"
echo 'hey there,ola,"Nice, command",ola' |awk -v FPAT='[^,]+|"[^"]+"' '{print $4}'
ola
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…