[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列还存在 能帮忙修改下吗 作者: csccyab 时间: 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"
作者: xin2v 时间: 2019-01-10 13:36
不对 输出报错 作者: csccyab 时间: 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"作者: csccyab 时间: 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"