Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Another Perl version:

perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' 

Example:

$ perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' foo John Doe <j*******@g***l.com> John Doe <j******@h*****l.net> Jane Doe <j****@o*****k.org> 

With sed, replacing the characters by an equal number of * is complicated. See this SO postthis SO post for examples involving sed, perl and awk.

Another Perl version:

perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' 

Example:

$ perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' foo John Doe <j*******@g***l.com> John Doe <j******@h*****l.net> Jane Doe <j****@o*****k.org> 

With sed, replacing the characters by an equal number of * is complicated. See this SO post for examples involving sed, perl and awk.

Another Perl version:

perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' 

Example:

$ perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' foo John Doe <j*******@g***l.com> John Doe <j******@h*****l.net> Jane Doe <j****@o*****k.org> 

With sed, replacing the characters by an equal number of * is complicated. See this SO post for examples involving sed, perl and awk.

Source Link
muru
  • 78.3k
  • 16
  • 214
  • 320

Another Perl version:

perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' 

Example:

$ perl -pe 's/(<.)(.*)(@.)(.*)(.\..*>)/$1."*" x length($2).$3."*" x length($4).$5/e' foo John Doe <j*******@g***l.com> John Doe <j******@h*****l.net> Jane Doe <j****@o*****k.org> 

With sed, replacing the characters by an equal number of * is complicated. See this SO post for examples involving sed, perl and awk.