Alister Kyle Alister Kyle - 5 months ago 24
Linux Question

Selecting strings and characters from variables in bash

I'm reading text in from a txt file, and I have to create a username from an email. The email address is in a single variable. The username must be the first letter of the users first name, and their entire last name. For example,'s username would be "jbloggs"

How do I select the first letter from the first name, then the entire last name, and concatenante them into 1 variable? I think I use the cut method but I'm unsure how to do it.


Answer Source
echo ${mailbox:0:1}${mailbox#*.}

The first line removes the domain. The second grabs the initial and then removes the whole first name to leave the last.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download