I'm doing analysis on a file and I want to mask some characters (while retaining their original byte count) before moving this file down the pipeline. For example, given file.txt:
Hello there Cory Klein
Have fun
Hello there Samantha Rodgers
Writing a regular expression to match the names and substituting them with XXXXX is pretty easy with sed:
$ sed -e "s/\(Hello there \).*/\1XXXXX/" file.txt
Hello there XXXXX
Have fun
Hello there XXXXX
But I would like to replace each character in the name with a X character, like so:
Hello there XXXX XXXXX
Have fun
Hello there XXXXXXXX XXXXXXX
How do I replace all characters matching a regular expression with another character?
Any regular POSIX tool is OK sed, awk, perl, etc. I'm sure I could write a simple python script to accomplish this, but I'm curious whether this is possible with regex alone, which would likely be more succinct. If so, I'd love to learn how so I could likely apply the concept in other places in the future.