Welcome to the Linux Foundation Forum!

Read file content with while and awk combined

Hi all,
I have a text file with the following content

Baluta, Mircea (M.C.) mbalu[email protected]; Ica, Victor Stefanita (V.I.) [email protected]; Badea
, Alexandra Nicoleta (A.B.) aba[email protected]>; Paun, Wily Robert (W.C.) [email protected]; S
toica, Bogdan (B.S.) [email protected]; Mitroi, Ilie (I.M.) [email protected]; Pirvu, Ion-Cri
stian (C.P.) [email protected]; Mihutoiu, Marius (M.M.) [email protected]; Ghita, Nuta (N.G.) ng
[email protected]; Vais, Marcel (M.V.) [email protected]; Dinuleasa, Marin-Catalin (M.D.) MDINULE
[email protected]; Sutiman, Amado Laviniu (A.S.) [email protected]; Ruiu, Marius-Sorin (M. S.) mr
[email protected]; Ivascu, Aurica (A. I.) [email protected]; Toma, Valter-Florian (V.T.) vtoma1@
yahoo.com; Siuinea, Ileana-Gabriela (I.S.) [email protected]; Minca, Angelica Doina (A. D.)
[email protected]; Till, Aurica-Marian (A.T.) [email protected]; Fiera, Mariana (M.F.) mfiera@f
ord.com; Mozoc, Vasile (V.S.) [email protected]; Tuca, Alexandru gabriel (A.T.) [email protected]
om; Radu, Adrian (A.R.) aradu2@yahoo.com; Mihaescu, Victor (V.M.) [email protected]; Ghita, D
orin (D. A.) [email protected]; Ardeleanu-Trusca, Daniel (D.A.) [email protected]; Marin, Ma
rius (M. G.) [email protected];

So every field is of form FirstName, LastName (M.C.) [email protected];
I want to display only user for all the users in the file

FILENAME="/home/ubuntu/user01.txt"
while reading LINES
do
echo $LINES | awk -F "@" '{print $1}' | awk '{print $NF}'
done < $FILENAME

So finally, as an example, the script only displays mbaluta for the user Baluta, Mircea (M.C.) [email protected]; and I would like to display it for everyone
Do you have any suggestions?

Categories

Upcoming Training