Search and replace in two different files

Hi there,

i got the following problem. i need a bash script to correct e-mail addresses in an csv. i got a huge csv like this

A                             B          C                D
heiner.holber.somewhere.ch    heiner    holber         heiner.holber@somewhere.ch

So A is the wrong Address and D ist the corrected Addressfield

No i want to correct this with a bash in the second csv file. So find A in the second file and correct it with D. The second file is not static.

Any idear? Thanks in Advance

Ralf

Hi and welcome, what did you try and where are you stuck?

i`m realy new in bash programming, so i stuck at the beginning :wall:

---------- Post updated at 04:05 PM ---------- Previous update was at 03:16 PM ----------

i found that to show the diff, but how can i read the columns?

diff <(sort file1) <(sort file2)

i write now the two first columns in a new file. now i have the e-mail address in the first column and if anything to correct, the second column with the new address

awk -F ";" '{print $1, $2}' test_org.csv > test-awk.csv

looks like

A.................................................                                                                             B 
heiner.holber.somewhere.ch..........              heiner.holber@somewhere.ch
heinz.hack@somewhere.ch
rosi_rodel@somewhere.ch                 ...........rosi.rodel@somewhere.ch

now i want to search in a second .csv file for the fields in column A and correct it there with the Field of B.
Please Help

---------- Post updated at 04:01 PM ---------- Previous update was at 01:40 PM ----------

awk -F ";" '{print $1, $2}' test_org.csv > test-awk.csv

is it possible to print out only this line, who have an entry on the second column?

nobody an idear??

Hi, it is not clear to me what you mean. What exactly doe the two csv files look like? With what character are they separated? Please give samples of all three.

hi Scrutinizer,

some backround information. we send a newsletter from our company. so many mails are running back, while the person changed the company, or the email was not correct. we have a receivers.csv where those people are listed right or wrong with subscribed or unsubscribed. the receivers.csv is a copy of the life receivers.csv on the webserver, so if we correct the things in the copy, the live csv would be filled up or changed.
now on the first column is the email address right or wrong, on the second column i want to write the right email address if its wrong. so when all the email addresses are corrected, i want to change with that script the life receivers.csv.
if there is an entry on the second column with an correted address so write it on the live .csv on the first column. the filds are separeted with this ; , i don`t know the name of it.

molker

Hi molker, so semicolon separated? In that case try this:

awk -F";" '$2{print $1,$2}' infile

Remember, a good example says more than 161 words..

hi Scrutinizer,

this is what i get now. i saw in column email the wrong and in column title the right one.

email title
orname.nachname@somewere.ch vorname.nachname@somewere.ch
nachname@somewhere.ch x.nachname@somewhere.ch
x.x@wggsp.ch x.nachname@somewhere.ch

is it now possible to look in the live file called receivers-live.csv for those 3 in the first column and correct it with the right one in the column title?

solved it

make it now with diff.-u and write it with pach to the original file

diff -u original.file old.file > mods.diff
patch < mods.diff 

thanks