简体   繁体   English

如何使用shell脚本解析文件

[英]How to parse a file using shell script

I am having a file : 我有一个文件:

abc@gmail.com
dba@gmail.com
xyz@gmail.com
//abc@gmail.com
//dba@gmail.com
//xyz@gmail.com
abc@gmail.com
dba@gmail.com
xyz@gmail.com

I want to write a script which parse the file and for the first occurrence of say abc@gmail it should remain as it is and for other occurrence if "//" found then ok otherwise add "//" at the starting of all other occurrence. 我想写一个解析文件的脚本,并且首次出现说abc @gmail它应保持原样,如果发现“//”则发生其他情况,否则在其他所有其他地方添加“//”发生。

You can use this awk command: 你可以使用这个awk命令:

awk '$1 in seen && !/^[[:blank:]]*\/\// { $0 = "//" $0 } !seen[$1]++{} 1' file
abc@gmail.com
dba@gmail.com
xyz@gmail.com
//abc@gmail.com
//dba@gmail.com
//xyz@gmail.com
//abc@gmail.com
//dba@gmail.com
//xyz@gmail.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM