I am trying to extract all emails of the line with awk. This is what I tried:
echo " test@test.com secondtest@test.com" | awk 'BEGIN{IGNORECASE = 1}{while(match($0,/[^\s@]+@[^\s@]+\.[a-z]{2,4}/, result) !=0 ) { printf "%s\\n",result[0]; $0 = sub(/[^\s@]+@[^\s@]+\.[a-z]{2,4}/,"", $0)}}'
But is doesn't work properly. I am expecting the following output:
test@test.com
secondtest@test.com