Posts Tagged ‘line’

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