Search and replace in two different files


 
Thread Tools Search this Thread
Top Forums Programming Search and replace in two different files
# 1  
Old 04-26-2012
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

Code:
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

Moderator's Comments:
Mod Comment Please do not use actual email addresses in a post. link: How to use [code] tags

Last edited by Scrutinizer; 04-26-2012 at 11:22 AM.. Reason: code tags / email address
# 2  
Old 04-26-2012
Hi and welcome, what did you try and where are you stuck?
# 3  
Old 04-26-2012
i`m realy new in bash programming, so i stuck at the beginning Smilie

---------- 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?

Code:
diff <(sort file1) <(sort file2)

# 4  
Old 04-30-2012
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

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

looks like

Code:
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 ----------

Code:
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??

Moderator's Comments:
Mod Comment Please click this link: How to use [code][/code] tags

Last edited by Scrutinizer; 05-01-2012 at 02:35 AM..
# 5  
Old 05-01-2012
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.
# 6  
Old 05-02-2012
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

Last edited by Scrutinizer; 05-02-2012 at 04:20 AM.. Reason: icode highlight of semicolon
# 7  
Old 05-02-2012
Hi molker, so semicolon separated? In that case try this:
Code:
awk -F";" '$2{print $1,$2}' infile

Remember, a good example says more than 161 words..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search in one type of files and replace

I am not sure how to search and replace the word in the few specific files. I need to search and replace word in only the name containing pepsi in the filename. (12 Replies)
Discussion started by: ramkumar15
12 Replies

2. Shell Programming and Scripting

Search replace with awk using 2 files

I have a bit of a complex problem that I would like to solve with awk. It is essentially a 2-part problem. I have a large directory of files with the same format, each with 266 lines. The first 206 lines of each file are filled with attribute information. Then the following 60 lines consist... (4 Replies)
Discussion started by: owwow14
4 Replies

3. Shell Programming and Scripting

Search and Replace in multiple files

Hello, I have hundreds of files in which I need to change email address. Here is what I am trying to do: 1. All text files are in a directory "a" 2. In the text file, I want to replace email address for preparer. All these lines start with {{PreparerEmail and end with }}. The email... (3 Replies)
Discussion started by: cartrider
3 Replies

4. Shell Programming and Scripting

Keyword search/replace for two text files?

What is the best way (bash/awk/sed?) to read in two text files and do a keyword search/replace? file1.txt: San Francisco Los Angeles Seattle Dallas file2.txt: I love Los Angeles. Coming to Dallas was the right choice. San Francisco is fun. Go to Seattle in the summer. ... (3 Replies)
Discussion started by: pxalpine
3 Replies

5. UNIX for Dummies Questions & Answers

Search and replace across files

Hi All, HP-UX oradev3 B.11.11 U 9000/800 3251073457 I have following files all contains text like "919642990137@". I need to search this text across all files and replace it with something like "919717298765@". I was wondering, how to accomplish this task? cpmprod_status.sh... (8 Replies)
Discussion started by: alok.behria
8 Replies

6. Shell Programming and Scripting

Search and replace string in files

I'm trying to remove the following string from several files. <img heigth="1" width="1" border="0" src="http://myteenmovies.net/t.php?id=5540372">I'm using the following script #!/bin/bash # This script will search and replace all regular files for a string # supplied by the user and... (1 Reply)
Discussion started by: d13g0sv
1 Replies

7. Shell Programming and Scripting

Search and replace text in many files

Hello, I am very new to Linux and am trying to find a way for following problem. I have a number of files in a folder as Export000.dat, Export001.dat ..and so on. Each file has a string field 'Absolute velocity'. I want it to be replaced by 'Pixel shift' in all the files. I tried something like... (4 Replies)
Discussion started by: chirag.joshi
4 Replies

8. Shell Programming and Scripting

search and replace in many files

I have a directory full of files. Most of the code in the files is the same accept for a few parameter values. I want to remove hard coded values and replace it with a parameter that I can pass. This is oracle pl/sql anonymous blocks. so the code is similiar to this function myfunc (p_myvar ... (1 Reply)
Discussion started by: guessingo
1 Replies

9. Shell Programming and Scripting

Search and Replace between two files

Hi all- I've got 2 files: One is the final results and one is a result set from a query. In the final results files I have placeholder strings in there that need to be replaced by the corresponding strings from the query file. So File#1 (FINAL RESULTS) LINEID CLIENT ID REP ... (1 Reply)
Discussion started by: Cailet
1 Replies

10. Shell Programming and Scripting

fast search and replace in all files

Hi I need to find one string in all files and replace tht string with blank space and need to redirect all the files into the same directory again. now i am using find ./ -name "*.dmp" | xargs perl -pi -e 's/\\N//g' | sed 's/.$//g' but now its not redirrecting properly . its taking... (21 Replies)
Discussion started by: dbsurf
21 Replies
Login or Register to Ask a Question