Posts Tagged ‘@’

Using sed to remove lines

So you have the following list of email addresses in the syntax user@uni.edu.au 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:

test1@uni.edu.au
test2@uni.edu.au
test3@uni.edu.au

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:

test1
test2
test3

….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

Advertisements