免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1020 | 回复: 4

[文本处理] 脚本问题 修改 [复制链接]

论坛徽章:
0
发表于 2019-01-10 11:10 |显示全部楼层
23列  ----红色是 23列

[root@sftp02 tmp]# cat 4.txt
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"1"|"2198"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"U.S. Citizen or U.S. National"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"Other (Non-US)"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"Other (test)"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|""|""|"330988"|"Buffalo Academy of Visual and Performing Arts"

[root@sftp02 tmp]#
[root@sftp02 tmp]#  awk 'BEGIN{FS=OFS="|"}{if($23~"Other (Non-US)"){NF=NF}else if($23~"U.S. Citizen or U.S. National|U.S. Dual Citizen|U.S. Permanent Resident"){$24="\042US\042"}else if($23~"\042\042"){$24="\042permanent address country\042"}}1' 4.txt

"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"1"|"2198"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"U.S. Citizen or U.S. National"|"US"|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"Other (Non-US)"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"Other (test)"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|""|"permanent address country"|"330988"|"Buffalo Academy of Visual and Performing Arts"

本来想的是 这个脚本执行完 替换后 23列是被删掉的 但是从结果看 23列还存在  能帮忙修改下吗

论坛徽章:
0
发表于 2019-01-10 11:44 |显示全部楼层
$ US\042"}else if($23~"\042\042"){$24="\042permanent address country\042";$23=""}}1' 4.txt                                                                <
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"1"|"2198"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"U.S. Citizen or U.S. National"|"US"|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"Other (Non-US)"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"Other (test)"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"||"permanent address country"|"330988"|"Buffalo Academy of Visual and Performing Arts"



论坛徽章:
0
发表于 2019-01-10 13:36 |显示全部楼层
不对 输出报错   

论坛徽章:
0
发表于 2019-01-10 14:07 |显示全部楼层
$ awk 'BEGIN{FS=OFS="|"}{if($23~"Other (Non-US)"){NF=NF}else if($23~"U.S. Citizen or U.S. National|U.S. Dual Citizen|U.S. Permanent Resident"){$24="\042US\042"}else if($23~"\042\042"){$24="\042permanent address country\042"}$23=""}1' 4.txt
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"1"|"2198"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"||"US"|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"||""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"||""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"||"permanent address country"|"330988"|"Buffalo Academy of Visual and Performing Arts"

论坛徽章:
0
发表于 2019-01-10 14:29 |显示全部楼层
$ awk 'BEGIN{FS=OFS="|"}{if($23~"Other (Non-US)"){NF=NF}else if($23~"U.S. Citizen or U.S. National|U.S. Dual Citizen|U.S. Permanent Resident"){$24="\042US\042"}else if($23~"\042\042"){$24="\042permanent address country\042"}} {for (i=1;i<23;i++) printf "%s|",$i; for(i=24;i<NF;i++) printf "%s|", $i; printf "%s\n", $NF}' 4.txt
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"1"|"2198"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"US"|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|""|"330988"|"Buffalo Academy of Visual and Performing Arts"
"ZHH_STUDENT"|"ZHH_SFDD"|"ZHH_ZHHCA"|"2198"|"P"|"21777848"|"Caitlin"|"Marie"|"Wilson"|""|"Female"|"75 Zittel St"|""|""|"Buffalo"|""|"New York"|"33234-333"|"United States of America"|"www@gmail.com"|"-9386.284"|"No"|"permanent address country"|"330988"|"Buffalo Academy of Visual and Performing Arts"
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

SACC2019中国系统架构师大会

【数字转型 架构演进】SACC2019中国系统架构师大会,7折限时优惠重磅来袭!
2019年10月31日~11月2日第11届中国系统架构师大会(SACC2019)将在北京隆重召开。四大主线并行的演讲模式,1个主会场、20个技术专场、超千人参与的会议规模,100+来自互联网、金融、制造业、电商等领域的嘉宾阵容,将为广大参会者提供一场最具价值的技术交流盛会。

限时七折期:2019年8月31日前


----------------------------------------

大会官网>>
  

北京盛拓优讯信息技术有限公司. 版权所有 16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122
中国互联网协会会员  联系我们:help@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP