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

时间:2016-07-11 22:32:45

标签: bash shell csv awk sed

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!

2 个答案:

答案 0 :(得分:3)

Using awk you can modify any particular column like this:

awk 'BEGIN{FS=OFS=","} {sub(/@.+/, "", $11)} 1' file.csv > newfile.csv

答案 1 :(得分:0)

希望这会有所帮助。

    cat csv1.csv | awk '{print $11}' | awk -F '@' '{print $1}'