Carbon
Carbon

Reputation: 143

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

[email protected]
[email protected]
[email protected]
[email protected]

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!

Upvotes: 1

Views: 159

Answers (2)

Faizan Younus
Faizan Younus

Reputation: 803

Hope this will help.

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

Upvotes: 0

anubhava
anubhava

Reputation: 784948

Using awk you can modify any particular column like this:

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

Upvotes: 3

Related Questions