Friday, September 4, 2015

Generate email filters in Gmail from list of emails

I have a lot of students from different classes who email me regularly. It is helpful to tell who belongs to which class. So I created a filter in Gmail which will sort the student's email according to their email ID. This scenario is also applicable to industry where we want to sort emails using filters. Most of the time people are able to do it by hand. However, for me it was challenging to do it by hand since I had 400 students. Therefore I fell back to Bash tools to automate the task.

The first thing is to extract all the email IDs from a CSV file and save it as a list.

cat file.csv | cut -d"," -f10

The 10th column had the email IDs in the CSV file. The fields are separated by commas in CSV files. Therefore, I have used -d"," as the delimiter in the cut command.


But they have the " which I need to get rid off. Easy use tr.

cat file.csv | cut -d"," -f12 | sed 's/"//'


The reason why I didn't get rid off the last " is because I am going to replace that with since these email IDs do no have the in them.

cat file.csv | cut -d"," -f12 | sed 's/"//' | sed 's/"/'


Save this list to a file tempfile1.

cat file.csv | cut -d"," -f12 | sed 's/"//' | sed 's/"/' > tempfile1

The reason why I can use . (dot) inside sed is because I used  ' ' instead of " "  so .(dot) is interpreted as . (dot) and not as a wildcard. 


SS said...

Cool tutorial.

Sudipta Ray said...

The title is kind of a tongue-twister in itself..:)

Print chess board in command line

The following bash one-liner will print a chess board in a terminal (the script works for the shells bash and ksh only) for (( i = 1; i ...