LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2011, 06:33 AM   #1
crowzie
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Rep: Reputation: Disabled
Text file column editing


Hello guys
I have 2 large text files , one looks like this:


<contact type="1">blahblah@hotmail.com</contact>
<contact type="1">blahblah2@hotmail.com</contact>
<contact type="1">blahblah3@hotmail.com</contact>

The other is a list of emails in single column format like this:


emailaddy@hotmail.com
emailaddy2@hotmail.com
emailaddy3@hotmail.com , etc
Is there a command to delete all the blahblah emails from text file 1 and replace them with the ones from text file 2?

Or maybe a linux version of 'Csved' which has the ability to add,remove,insert columns?
Thanks in advance.

(Im sure seymour Berkoff from La femme Nikita uses linux!)
 
Old 07-17-2011, 06:51 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by crowzie View Post
Is there a command to delete all the blahblah emails from text file 1 and replace them with the ones from text file 2?
Replace them with what addresses from file 2?
 
Old 07-17-2011, 06:54 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Assuming your examples are correct, why do you need to replace? Why not use the second file and place the tags around it:
Code:
$ cat infile2 
emailaddy@hotmail.com
emailaddy2@hotmail.com
emailaddy3@hotmail.com

$ sed 's%\(.*\)%<contact type="1">\1</contact>%' infile2
<contact type="1">emailaddy@hotmail.com</contact>
<contact type="1">emailaddy2@hotmail.com</contact>
<contact type="1">emailaddy3@hotmail.com</contact>
If this is what you want/need, you can let sed change in place by adding the -i flag:
Code:
sed -i 's%\(.*\)%<contact type="1">\1</contact>%' infile2
Hope this helps.
 
1 members found this post helpful.
Old 07-17-2011, 06:56 AM   #4
crowzie
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
There are 1000 emails in both text files.
I want to replace each email in file 1 with one from file two, It will be a perfect fit.
 
Old 07-17-2011, 07:22 AM   #5
crowzie
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Thanks druuna
You are the man!
 
Old 07-17-2011, 07:25 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Insert a column of text to a text file docaia Linux - Newbie 5 06-02-2011 10:55 AM
[SOLVED] Need to add a column to a text file Thaidog Programming 2 04-28-2011 09:09 AM
Read text file column by column RVF16 Programming 11 05-31-2009 07:16 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
ripping a column from a text file dominant Linux - Newbie 1 01-31-2006 04:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration