How to parse a file using a shell script

I have 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 that parse a file and for the first occurrence say abc @gmail it should stay as it is and for another event if "//" is found then add "//" to the beginning otherwise all other cases.

+3


source to share


1 answer


You can use this awk command:



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

      

+2


source







All Articles