Reputation: 425
I have an email like [email protected]
and the output should be first_last
I tried delimiting on @
first and then replaced .
with _
Is there an easier single line way to do it without using IFS?
Upvotes: 0
Views: 91
Reputation: 241988
You can use parameter expansion:
#! /bin/bash
[email protected]
name=${email%@*} # Remove everything after the last @.
name=${name//./_} # Replace all dots by underscores.
echo "$name"
Upvotes: 1