user2023
user2023

Reputation: 478

How to get the Full name to be sorted from the outlook type email address

I have below e-mail address from which i want names only like Abrar Ahmad and just remove or ignore email address getting printed.

Abrar Ahmad <[email protected]>; Andre Geurts <[email protected]>; Andrzej Kamionek <[email protected]>

I have tried below but did not get the desired.

$ awk '{ gsub( /<>/ , "" ) ;  print $1,$2  }' email
Abrar Ahmad

Upvotes: 0

Views: 39

Answers (2)

RavinderSingh13
RavinderSingh13

Reputation: 133700

1st solution: Could you please try following.

awk 'BEGIN{FS=OFS=";"} {for(i=1;i<=NF;i++){sub(/ <.*/,"",$i)}} 1'  Input_file

OR to make comma as a output separator try:

awk 'BEGIN{FS=";";OFS=","} {for(i=1;i<=NF;i++){sub(/ <.*/,"",$i)}} 1'  Input_file


2nd solution: OR try with split:

awk 'BEGIN{FS=OFS=";"} {for(i=1;i<=NF;i++){split($i,array,"<");$i=array[1]}} 1' Input_file

To make , as output separator try:

awk 'BEGIN{FS=";";OFS=","} {for(i=1;i<=NF;i++){split($i,array,"<");$i=array[1]}} 1'  Input_file

Upvotes: 2

James Brown
James Brown

Reputation: 37464

Something like this?:

$ awk '{gsub(/<[^<]*>/,"")}1' file
Abrar Ahmad ; Andre Geurts ; Andrzej Kamionek 

Upvotes: 3

Related Questions