LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-30-2007, 07:05 PM   #1
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Rep: Reputation: 30
Can VI Do This?? Delete before a character in text - Maybe advanced.


Hello,

I have a large number of email addresses that I would like to cut down to the domain. For example:

blah@microsoft.com
12345@yahoo.com
webmaster@google.com

What I want to know is, is there a command that will go through the entire list (over 1000 lines) and delete all characters before the @ symbol? Since they are of different lengths, I can't do a simple search and delete/replace. Anyways, I don't know if it's possible, but if it is, I imagine this would be the place for the answer. Google didn't provide me with a definitive answer, so I thought I'd check here. Thank you in advance!

Scine
 
Old 04-30-2007, 07:16 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
:%s/^.*\@//
 
Old 04-30-2007, 07:27 PM   #3
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by osor
:%s/^.*\@//

Tried that one, but I get

E62: Nested \@
E476: Invalid command.

Odd. Tried swapping / for \ and vice versa as well as a few other variant ideas. Ideas? By the way, thanks for the quick reply!

Scine
 
Old 04-30-2007, 07:44 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Are you using vi or vim? Vim might have a magic setting, in which case you don’t need to escape the @ at all just plain:
Code:
:%s/^.*@//
P.S. what’s Scine?
 
Old 04-30-2007, 07:47 PM   #5
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by osor
Are you using vi or vim? Vim might have a magic setting, in which case you don’t need to escape the @ at all just plain:
Code:
:%s/^.*@//
P.S. what’s Scine?

I'm using vi. I tried your code, and it did work somewhat. It brought my email list from blah@microsoft.com to microsoft.com. However, I found a bit of tinkering with your code and got it to work. I used this and it worked perfectly.

%s/^.*[@]/*@/

The above code made blah@microsoft.com to *@microsoft.com

Thank you very much for all your help.

P.S. Scine is a nickname I've had for a good long while. Force of habit when signing my name I guess. Thanks again!

Scine
 
Old 04-30-2007, 07:50 PM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Should work, but the actual command is:

sed -i s/^.*\@//g yourfile.txt

jlinkels
 
Old 04-30-2007, 07:57 PM   #7
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jlinkels
Should work, but the actual command is:

sed -i s/^.*\@//g yourfile.txt

jlinkels

Thank you very much for the info! Although I must admit, my "sed" abilities aren't where I'd like them to be. I've been running linux for the better part of a few years now, and I'm comfortable with many aspects of it, I must admit that I'm not too familiar with some more popular parts such as sed and awk. But I did notice this particular bit of knowledge helped me out in another area of my project. Thank you very much!

Scine
 
Old 05-01-2007, 10:01 AM   #8
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by tbeehler
It brought my email list from blah@microsoft.com to microsoft.com.
Oops, I must have misread the OP. I thought this is what you wanted.
 
Old 05-01-2007, 10:11 AM   #9
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by osor
Oops, I must have misread the OP. I thought this is what you wanted.
No problem at all. I appreciate all your help! Thanks again!

Scine
 
Old 05-07-2007, 05:02 PM   #10
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Original Poster
Rep: Reputation: 30
As a side note, to do the opposite, that is to delete everything past a certain character, I used %s/com./com That would replace blah@microsoft.com=username@#$@#$ with blah@microsoft.com It was a part of a project I'm working on, but thought I would mention it to help other people out.

Scine
 
  


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
vi editor - how to delete a character in each row of a column? flipwhy Linux - Newbie 6 01-22-2007 02:12 PM
Advanced Linux Sort text file Command soulxcavtor Linux - Software 1 06-07-2006 10:58 PM
vi command to find and delete all lines beginning with a character geomatt Linux - Software 8 12-20-2004 03:30 AM
Semi-Advanced Text Editor cspos Linux - Software 9 10-27-2004 11:31 AM
Reverse and Squeezing of text of character in C egoleo Programming 1 03-19-2004 09:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:38 AM.

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