Rize S. answered 03/23/23
Senior IT Certified Trainer, IT Developer & DBA Administrator
The AWK command to find all lines that have an email address and place a label "email =" before the line in the file longfile can be:
awk '/(from:|to:|Cc:|To:|cc:).*[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/ { print "email =", $0 }' longfile
This command uses regular expressions to match lines that contain an email address, and then prints the label "email =" followed by the entire matched line. The regular expression used here is not foolproof and may miss some email addresses or match some invalid ones, but it should work for most common cases.