Perl One Liner

Today I had to add a list of users to a service (knowbe4). I could have done it manually but I decided to use Perl to do it which (I think) made me gain a lot of time.

Instead of checking the current subscribed users, see which one to delete and which one to add manually (would have taken a lot of time since there are a lot of users already and even more users to add).

The format for to_add.csv was like this:

First Name,Second Name,Email Address

So here I share the one liner I came up with:

perl -ne 'chomp;/,([^,]+)$/;$#ARGV==0 ? $keep{lc $1}=$_ :exists $keep{lc $_} ? print $keep{lc $_},"\n" : warn $_, "\n"' to_add.csv already_in_mail 1>test_keep.csv 2>test_remove.csv

Here is how it works: