我有一个 csv 列表,想导入到 Google。我从 Google 下载了基本示例,如下所示:cat contacts.csv
Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Language,Photo,Group Membership,E-mail 1 - Type,E-mail 1 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value
A Name,A,,Name,,,,,,,,,,,,,,,,,,,,,,,,,* myContacts,* ,[email protected],Mobile,+number,Versão antiga,+number
然后我有一个列表:
name 1,email 1,49292304
name 2,email,3943984338
...
我编写了以下 awk 命令:
awk -F "," {'sub("\r$", ""); print $1",,,,,,,,,,,,,,,,,,,,,,,,,,,,,," $2",",","$3","","'} alunos.csv
它为我生成了一个正确的 CSV 文件,似乎根据谷歌提供的示例,但我在导入时间时出现错误。我遗漏了什么?
答案1
将标题行添加到 CSV。
awk -F "," 'BEGIN { print "Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Language,Photo,Group Membership,E-mail 1 - Type,E-mail 1 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value" } {'sub("\r$", ""); print $1",,,,,,,,,,,,,,,,,,,,,,,,,,,,,," $2",",","$3","","'}' alunos.csv