Replace my perl with awk or sed

My code below will print only the email address from all lines. I want to convert it with sed or awk.. also what if i just want to find only filenames.

cat LIS_EMAIL | perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}'

Hoping to extract the filename such us .exe, .bin. From file that has scrambled lines.

Thanks

awk '{for (i=1; i<=NF; i++) {gsub(/[^A-Za-z0-9_@.-]/, "", $i); sub(/^[.]*/, "", $i); sub(/[.]*$/, "", $i); if ($i ~ /.@.+[.].+/) print $i}}' LIS_EMAIL

I want something like..

#cat list_of
ajsdfjasldfjasdflkasdfasdfsdaf klasjfklas aa.exe skdfjasdkljf
slkadjfaskljfsdfmsdf aa.bin akljdajs
lkajskjnnn  aaa sssss gggg 11111 bb.exe



# cat list_of|grep -E ".exe|bin"
aa.exe
aa.bin
bb.exe

So - do you want e-mail addresses and / or / xor file names? Seems you go for sort of MS style files? Please be aware that on *nix systems, ". extension" is ad libitum, and file names can contain nearly any character except the slash / . It may become difficult to identify the file names in a line...

awk '{for (i=1; i<=NF; i++) {w=$i; sub(".*[.]", ".", w) ; if (ext "$" ~ w) print $i}}' ext=".bin,.exe" list_of

If you have grep -o ,

for the email addresses (even though a lot more characters are allowed, but this is what the perl says):

grep -Eo '[[:alnum:]_.-]+@[[:alnum:]_.-]+[[:alnum:]]+'

Filenames such as foo.exe or bar.bin:

grep -Eo '[[:alnum:]_.-]+\.(bin|exe)'
1 Like

that doesnt work i tried it.
but thank you though.

---------- Post updated at 01:24 AM ---------- Previous update was at 01:20 AM ----------

It works.. Thank you so much

[@soctxadm01:~]$ grep .mml list_fi |wc -l
841
[@soctxadm01:~]$

[@soctxadm01:~]$  grep -Eo '[[:alnum:].-]+\.(mml)' list_fi|sort|uniq|wc -l
841

can you please explain the for me ..

 grep -Eo '[[:alnum:].-]+\.(mml) - character per character..

You are welcome. I made one correction in my post.. Added underscores which are also word characters..

-E               Use extended regular expressions
-o               Print only the matched (non-empty) parts of a matching line, 
                 with each such part on a separate output line
[[:alnum:].-]+   One or more alphanumeric character or underscore, dot or dash.
\.               A literal dot
(bin|exe)        Either the string "bin" or the string "exe"

older grep don't have -o option, in that case following your example just say

tr ' ' '\n' < list_of | grep -E '\.exe|\.bin'