I have to write a script which will mask the sensitive data in the log files. I am confused how to implement this? Which option will be best for doing the same:
- Using AWK
- Using SED
- Using SED,AWK
- Using PERL
- Using simple file read and searching logic.
If you have any suggestions then please share.
Input File:
Name Jack
Add New York
Phone 333-333-3434
Output File:
Name Jack
Add New York
Phone XXX-XXX-XXXX
I tried this using awk:
cat $HOME_DIR/testdata.dat | awk 'BEGIN{
i=1;
FS=" ";
}
{
for (i = 1; i < NF; i++) {
fld = $(i);
if( fld == "PHONE") {
printf ("%s$%s", $(i),$(i+1));
}
else if( fld == "PIN") {
printf ("%s$%s", $(i),$(i+1));
}
else if( fld == "DOB") {
printf ("%s$%s", $(i),$(i+1));
} else {
printf ("%s", $(i));
}
}
printf ("\n");
}
END{
i=1
}' > $HOME_DIR/testdataupd.dat
One way using
awk. When found wordsphone,doborpinat the beginning of the line (ignoring case) substitute in second field all characters but-withX. Theprintcommand is executed for every line.