Using sed to remove lines

So you have the following list of email addresses in the syntax and you want to strip out everything after the @ sign leaving you will a list of usernames. The user names need then to be on one line only.

So for example if the file called “email_list” looked like this:

To get the first part working:

# cat email_list | sed ‘s/@.*//’

Meaning everything after the @ replace with nothing.

You will get a list like this:


….but we want the output all on one line to be able to copy and paste it:

# echo $(cat email | sed ‘s/@.*//’)

Now you get:

test1 test2 test3


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: