Home > Net >  How to split a name from middle name and last name in a list with Bash Shell Script
How to split a name from middle name and last name in a list with Bash Shell Script

Time:04-14

First of all, thank you so much for taking some time out to help me out! I've been trying to figure out a way to split a full name into First, Middle, and Last names using awk and sed in bash shell without any success, this is an example of the names.

Kent D. Hones
Akelli Same Lizarraga
Sherein Rahmi
Theresa Q. Callins
Vanessa M. Dewson
Behzad Gazloo
Jim M. Skolen
Sherry Marie Wanaa

These are the bash commands that I've been trying to use.

awk -F"." '{print $1}' listnames.csv > output.csv
sed -e 's/*.//g' <  listnames.csv > output.csv

The output of the used commands are:

for awk -F"." '{print $1}' listnames.csv > output.csv returns an empty output.csv for sed -e 's/*.//g' < listnames.csv > output.csv returns the exact same list:

Kelly D. Hynes
Aketzalli Gamez Lizarraga
Shervin Rahimi
Theresa M. Collins
Vanessa L. Dawson
Behzad Garagozloo
James M. Skaalen
Shannon Marie Wenaa

The desired output is to have at least two list of

First name 
Aketzalli  
Shervin
Theresa
Vanessa
Behzad
James
Shannon

Last name
Hynes
Lizarraga
Rahimi
Collins
Dawson
Garagozloo
Skaalen
Wenaa

I was thinking that maybe I could use the "." in the Middle name to differentiate them but that would not work for distinguishing between last names and middle names.

Any help, insights, or feedback would be much appreciated. Thanks!

  • Related