从 csv 文件的 1 列中删除前导零
Removing leading zeros from 1 column of a csv file
我正在寻找一种从 CSV 文件的第一列中删除前导零的快速方法,以便其他程序可以很好地使用它。如果可能的话,最好也将其从逗号分隔转换为制表符分隔,但这可能必须是一个单独的问题。
这里是 header 个名字(只需要从学生 ID 中去掉前导 (2) 个零):
"Student ID","School Name","Contact Relation","Contact First Name","Contact Last Name","Salutation"," Home Phone Number","Address Line 1","Address Line 2","City","State","Zip","Zip + 4","Work Phone","Cell Phone","Pager","Residential Status","Custodial Status"
下面是一些示例数据,以了解其格式:
"004000031","Local High School","Mother","FirstName","LastName","","555-5557773","555 Old Midlothian Tpke","Lot77","Richmond","VA","23222","","","","","","Y"
这个 perl 应该可以为您完成。
第一个表达式删除每行的前两个零。
第二个将 ,
更改为制表符。
perl -pne 's/^00//;s/,/\t/g' your_file.txt
这一行应该这样做:
String[] tokens = String.join("\t", csv.replaceFirst("^\"0*", "\"").split(","));
修改了生成 CSV 文件的 XML 代码。只需要add/modify 2行
<field id="stdIDLocal" header-source="field" header-value="Student ID" find="00" replaceFirst="" />
要将输出从 CSV 转换为制表符分隔文件,请在您的标记中使用以下 XML 语句:
<export table-id="tblStudent" header-row="true" value-delimiter="	" >
我正在寻找一种从 CSV 文件的第一列中删除前导零的快速方法,以便其他程序可以很好地使用它。如果可能的话,最好也将其从逗号分隔转换为制表符分隔,但这可能必须是一个单独的问题。
这里是 header 个名字(只需要从学生 ID 中去掉前导 (2) 个零):
"Student ID","School Name","Contact Relation","Contact First Name","Contact Last Name","Salutation"," Home Phone Number","Address Line 1","Address Line 2","City","State","Zip","Zip + 4","Work Phone","Cell Phone","Pager","Residential Status","Custodial Status"
下面是一些示例数据,以了解其格式:
"004000031","Local High School","Mother","FirstName","LastName","","555-5557773","555 Old Midlothian Tpke","Lot77","Richmond","VA","23222","","","","","","Y"
这个 perl 应该可以为您完成。
第一个表达式删除每行的前两个零。
第二个将 ,
更改为制表符。
perl -pne 's/^00//;s/,/\t/g' your_file.txt
这一行应该这样做:
String[] tokens = String.join("\t", csv.replaceFirst("^\"0*", "\"").split(","));
修改了生成 CSV 文件的 XML 代码。只需要add/modify 2行
<field id="stdIDLocal" header-source="field" header-value="Student ID" find="00" replaceFirst="" />
要将输出从 CSV 转换为制表符分隔文件,请在您的标记中使用以下 XML 语句:
<export table-id="tblStudent" header-row="true" value-delimiter="	" >