Replace Content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace Content
# 1  
Old 06-11-2015
Replace Content

Hello all ; )

I'got a file1 with a lot of emails like :

Code:
fistname.lastname@domaine1.com

And another file2 with emails like

Code:
fistname.lastname@domaine2.ct.net

I need a shell script that will read each line from the file1 and try to find if in file2 the
Code:
fistname.lastname

exist.

If yes, the script will have to replace on the file1 the
Code:
@domaine1.com

by
Code:
@domaine2.ct.net

If not do nothing.

Thanks a lot for your help

ex :
File1
Code:
az.et@qsdf.com
sdf.zet@qsdf.com

File2
Code:
az.et@wxc.cc.net

at the end of the script only the first line on file1 will be updated :

New file1 will look like this :

Code:
az.et@wxc.cc.net
sdf.zet@qsdf.com

Becarefull the script sould not be case sensitive as some adresses may be on lower or upper case.

Last edited by Scrutinizer; 06-11-2015 at 11:40 AM.. Reason: Additional code tags
# 2  
Old 06-11-2015
Hi try:
Code:
awk '{i=tolower($1)} NR==FNR{A[i]=$2; next} i in A{$2=A[i]}1' FS=@ OFS=@ file2 file1


Last edited by Scrutinizer; 06-11-2015 at 11:42 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mysql Content Replace

I have a wordpress site. I need add "post_title" to all my "post_content" mysql field. Thanks. my content: Free <b>Online Tips</b> output:Free post_title <b>Online Tips</b>: This code does not work: UPDATE wp_posts SET post_content = REPLACE ( post_content, 'Free <b>Online... (0 Replies)
Discussion started by: tara123
0 Replies

2. Shell Programming and Scripting

Help with replace all the content within ()

Hi, Below is my input file : AAAG(12) TC(14) AACCCT(66) AACCCT(30) AACCCT(18) AACCCT(48) TCTG(12) TCTG(20) TCTG(16) AC(12) AC(12) TCTG(16) TCTG(12) AC(12) AC(12) AC(12) AC(26) AC(14) AGTG(12) AC(24) AGTG(12) TCC(12) Desired output : AAAG TC AACCCT AACCCT AACCCT AACCCT TCTG TCTG... (4 Replies)
Discussion started by: perl_beginner
4 Replies

3. Shell Programming and Scripting

How to replace multiple file content?

Hi Gurus, I need replace multiple files content. the file name pattern likes currentfile_code_* the content pattern in the file like text=value I need replace the content as text=abcde Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

4. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

5. Shell Programming and Scripting

Help with replace duplicate content

Input file: CCNI data564_input1 264 CORO1A data564_input2 155 ABC-B data17_input1 3466 ABC-B data17_input2 1133 ABC-B data17_input3 2162 ABC-B data17_input4 2019 HNRNPA2B1 data95_input1 101 HNRNPA2B1 data95_input2 340 IFITM1 data105_input2 291 IFITM2 data105_input1 505... (3 Replies)
Discussion started by: cpp_beginner
3 Replies

6. Shell Programming and Scripting

Help with replace data content

Format of one input file: # >length=1 seq program data 909 1992 seq program record 909 1190 Desired output result: # >length=1 length=1 program data 909 1992 length=1 program record 909 1190 I wanna to replace all the column 1 content (exclude the content start with "#") with the... (5 Replies)
Discussion started by: cpp_beginner
5 Replies

7. Shell Programming and Scripting

Replace file content after checking value

Our system is receiving one feed from the third party. One of the field in the flat file is ID which id from position 19 to 27. In some cases this ID is coming as 9 zeros (000000000) or 1 right padded zero. ( 0) For these specific records I want to replace fthis field with blank... (3 Replies)
Discussion started by: varunrbs
3 Replies

8. Shell Programming and Scripting

search and replace the content

Hi All,sorry for inconvience....please find the attachement for my question i am unable to paste the question here....please help me in slving thisthanksk.k (4 Replies)
Discussion started by: G.K.K
4 Replies

9. Shell Programming and Scripting

How to replace a line content

Hi Experts, I have binary files contain an ID Line as: : : $Header: FNDSCMON.fmb 115.6 2000/01/11 10:26:10 pkm ship$ : : where the ID Line format is: $Header: <File_Name> <Version> <Last_update_date_time> pkm ship$ In this Example: File_Name = FNDSCMON.fmb Version = 115.6... (13 Replies)
Discussion started by: victorcheung
13 Replies

10. Shell Programming and Scripting

How to replace a variable content

Hi, variable1="This is a car" Now I want to replace the content of variable1, "car" to "dog". Is there any simple command I can use. Thanks. Joseph (4 Replies)
Discussion started by: josephwong
4 Replies
Login or Register to Ask a Question