로 삼았 출력 :
awk -f getFields.awk input.txt
input.txt
당신의 입력 파일입니다
및 getFields.awk
은 다음과 같습니다
{
split("",a)
splitLine()
print a[1],a[3]
}
function splitLine(s,indq,t,r,len) {
# Assumptions:
# * spaces before or after commas are ignored
# * spaces at beginning or end of line is ignored
# definition of a quoted parameter:
# - starts with: (^ and $ are regexp characters)
# a) ^"
# b) ,"
# - ends with:
# a) "$
# b) ",
s=$0; k=1
s=removeBlanks(s)
while (s) {
if (substr(s,1,1)=="\"")
indq=2
else {
sub(/[[:blank:]]*,[[:blank:]]*"/,",\"",s)
indq=index(s,",\"")
if (indq) {
t=substr(s,1,indq-1)
splitCommaString(t)
indq=indq+2
}
}
if (indq) {
s=substr(s,indq)
sub(/"[[:blank:]]*,/,"\",",s)
len=index(s,"\",") #find closing quote
if (!len) {
if (match(s,/"$/)) {
len=RSTART-1
}
else
len=length(s)
r=substr(s,1,len)
s=""
} else {
r=substr(s,1,len-1)
s=substr(s,len+2)
}
a[k++]=r
} else {
splitCommaString(s)
s=""
}
}
k=k-1
}
function splitCommaString(t,b,i) {
n=split(t,b,",")
for (i=1; i<=n; i++)
a[k++]=removeBlanks(b[i])
}
function removeBlanks(r) {
sub(/^[[:blank:]]*/,"",r)
sub(/[[:blank:]]*$/,"",r)
return r
}
을
중복 가능성 http://stackoverflow.com/questio ns/7804673/escaping-separator-in-double-quotes) – pfnuesel
첫 번째 큰 따옴표로 묶인 섹션에 항상 쉼표가 두 개 있으면'cut -d ','-f1-3,5' – n0741337