Carbon Carbon - 4 months ago 8
Bash Question

How to delete end of String in CSV file shell script?

I have a csv file that has over 10,000 entries called csv1.csv that I need to manipulate. I want to change the 11th column all the values which contain the email addresses of different people.
What I have right now in column 11:

E-mail Address

Hi@yahoo.com
What@yahoo.com
Up@yahoo.com
lol@yahoo.com


Desired output:

Hi
What
Up
lol


I also want to keep all other 12 columns the same and use redirect > to put in another csv file. So essentially only taking out the @yahoo.com, but keeping whatever is in front of the string. Any help would be appreciated! Thanks!

Answer

Using awk you can modify any particular column like this:

awk -F, '{sub(/@.+/, "", $11)} 1' file.csv > newfile.csv
Comments