Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:18:24+00:00 2026-06-05T07:18:24+00:00

Q1: I would like to edit a file containing a set of email ids

  • 0

Q1:
I would like to edit a file containing a set of email ids such that all the domain names become generic.

Example,
peter@yahoo.com
peter@hotmail.co.in
philip@gmail.com

to
peter_yahoo@generic.com
peter_hotmail@generic.com
philip_gmail@generic.com

I used the following sed cmd to replace @ with _

sed 's/@/_/' <filename>

Is there a way to append another sed cmd to the cmd mentioned above such that I can replace the last part of the domain names with @generic.com?

Q2:
so how do I approach this if I had text at the end of my domain names?

Example,
peter@yahoo.com,i am peter
peter@hotmail.co.in,i am also peter

To,
peter_yahoo.com@generic.com,i am peter
peter_hotmail.co.in@generic.com,i am also peter

I tried @(,) instead of @(.*)
it doesn’t work and I cant think of any other solution

Q3:
Suppose if my example is like this,

peter@yahoo.com
peter@hotmail.co.in,i am peter

I want my result to be as follows,

peter_yahoo.com@generic.com
peter_hotmail.co.in@generic.com,i am peter,i am peter

How do i do this with a single sed cmd?

The following cmd would result in,

sed -r 's!@(.*)!_\1@generic.com!' FILE

peter_yahoo.com@generic.com
peter_hotmail.co.in,i am peter,i am peter@generic.com

And the following cmd wont work on “peter@yahoo.com”,

sed -r 's!@(.*)(,.*)!_\1@generic.com!' FILE

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:18:25+00:00Added an answer on June 5, 2026 at 7:18 am

    Golfing =)

    $ cat FILE
    Example,
    peter@yahoo.com
    peter@hotmail.co.in
    philip@gmail.com
    
    $ sed -r 's!@(.*)!_\1@generic.com!' FILE
    Example,
    peter_yahoo.com@generic.com
    peter_hotmail.co.in@generic.com
    philip_gmail.com@generic.com
    

    In reply to user1428900, this is some explanations :

    sed -r          # sed in extended regex mode
    s               # substitution
    !               # my delimiter, pick up anything you want instead !part of regex
    @(.*)           # a literal "@" + capture of the rest of the line
    !               # middle delimiter
    _\1@generic.com # an "_" + the captured group N°1 + "@generic.com"
    !               # end delimiter
    FILE            # file-name
    

    Extended mode isn’t really needed there, consider the same following snippet in BRE (basic regex) mode :

     sed 's!@\(.*\)!_\1@generic.com!' FILE
    

    Edit to fit your new needs :

    $ cat FILE
    Example,
    peter@yahoo.com,I am peter
    peter@hotmail.co.in
    philip@gmail.com
    
    
    $ sed -r 's!@(.*),.*!_\1@generic.com!' FILE
    Example,
    peter_yahoo.com@generic.com
    peter@hotmail.co.in
    philip@gmail.com
    

    If you want only email lines, you can do something like that :

    sed -r '/@/s!@(.*),.*!_\1@generic.com!' FILE
    

    the /@/ part means to only works on the lines containing the character @

    Edit2:

    if you want to keep the end lines like your new comments said :

    sed -r 's!@(.*)(,.*)!_\1@generic.com\2!' FILE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to edit a file containing a set of email ids such
I have this line: $(#clients-edit-wrapper).height($(window).height()-150); I would like to apply that height function to
I have hundreds of folders each containing a zip file. I would like to
How would you generate an JPG image file containing data fields that are stored
I would like to edit matlab scripts in two cases (1) In matlab Command
I'm working in Visual Studio 2008 and I would like for Edit > Outlining
I would like to place an edit control (WC_EDIT) on a static control (WC_STATIC).
I would like to know how I could edit mp3 files on the server
I would like to write a script which will edit multiple XML files, I
I would like the user to be able to edit the title of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.