Reputation: 146
I have name column. I need to built email address using name, for example
name email
Susan Black [email protected]
maria Kramer [email protected]
I think to write a regex to remove substring from first position to a space character and add "@abc.com" to end, then using sed do it lowercase. Is this a good idea and how can i realize it?
Upvotes: -1
Views: 194
Reputation: 12887
Using sed:
sed -rn 's/(^[[:alpha:]]{1})(.*[[:space:]])(.*$)/\1\[email protected]/;s/[[:upper:]]/\L&/gp' file
Using sed with regular expression interpretation (-r or -E) split the names into three sections and print the first (first initial) and the third (surname) followed by "@abc.com". We then search for upper case characters and use \L& to convert them to lowercase
Upvotes: 1
Reputation: 36620
I would use AWK
for this following way, let file.txt
content be
Susan Black
maria Kramer
then
awk '{print tolower(substr($1,1,1) $2) "@abc.com"}' file.txt
output
[email protected]
[email protected]
Explanation: get 1-long substring starting at 1st position from 1st column, concat it with 2nd column, make this lowercase then concat with @abc.com
, print
such constructed string.
(tested in gawk 4.2.1)
Upvotes: 2