-4

can I make this work with basic shell tools(no Python or Perl)?

INPUT1:

file1.csv
    John,Doe,john@mail.com
    Andy,Barry,barry@mail.com
    Mary,,mary@yahoo.com

count occurencies of emails from 3rd column,file1 in INPUT2:

file2.log
    mary@yahoo.com&fghfgh
    asdda&barry@mail.com
    barry@mail.com&werewr

desired OUTPUT:

result.csv
    John,Doe,john@mail.com,0
    Andy,Barry,barry@mail.com,2
    Mary,,mary@yahoo.com,1

many thanx!

2
  • Please provide the proper input file in your question. Dec 16 '16 at 16:29
  • Maybe now it's clearer, sorry for problems in question formulation. Dec 20 '16 at 14:48
0

You didn't provide valid input, so I used this:

John,Doe,barry@mail.com
Andy,Barry,barry@mail.com
Mary,,mary@yahoo.com

For which the following awk one-liner gives expected results:

awk -F, '{l[NR]=$0;f[NR]=$3;c[$3]++}END{for(i=1;i<=NR;i++)print l[i] "," c[f[i]]}'

The issue here is that your task requires either two passes. (f[] is just a convenience to avoid keeping the entire content parsed, or re-parsing it at the end.) But since I don't understand why you ruled out python or perl (they are basic shell tools), perhaps you don't consider awk fair game either...

1
  • Hi, thanx for Your answer. Please, recheck the question, I've edited. I need to input 1 csv file and compare vs another file/s and count occurencies in a second file, not in the first. Awk is ok. Dec 16 '16 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.