1

Compare two files if second file contains a domain which is not found in first file than add "Static" in second field.

File1:

cleanwatersaveslives.com      WordPress
blood-mate.com                CodeIgniter
brotex.com                    WordPress

File2:

brotex.com
blood-mate.com
cleanwatersaveslives.com
suhailacademy.com
damiastudioz.com              
support.techpublications.org  
techpublications.org          
tekstilworks.com              

What i want to get is:

cleanwatersaveslives.com      WordPress
blood-mate.com                CodeIgniter
brotex.com                    WordPress
suhailacademy.com             Static
damiastudioz.com              Static
support.techpublications.org  Static
techpublications.org          Static
tekstilworks.com              Static
4
  • When i run awk 'BEGIN {FS=OFS="\t"} NR==FNR {v[$1]=$2} {print $1, (v[$1] ? v[$1] : "static")}' dynamic userdomains | column -t It gives: blood-mate.com CodeIgniter Static brotex.com WordPress Static suhailacademy.com Static damiastudioz.com Static
    – blaCkninJa
    Jun 3, 2016 at 21:17
  • That's easy to fix but there is no cleanwatersaveslives.com in file2 so why is that present in your output ? You said "compare" not "merge"... Run awk 'NR==FNR {v[$1]=$2;next} {print $1, (v[$1] ? v[$1] : "static")}' file1 file2 | column -t Jun 3, 2016 at 21:25
  • It's added, mistakenly missed in file2.
    – blaCkninJa
    Jun 3, 2016 at 21:28
  • Yes it's working thanks, i'll be careful next time.
    – blaCkninJa
    Jun 3, 2016 at 21:51

0

Browse other questions tagged .