Reputation: 478
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
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
Reputation: 37464
Something like this?:
$ awk '{gsub(/<[^<]*>/,"")}1' file
Abrar Ahmad ; Andre Geurts ; Andrzej Kamionek
Upvotes: 3