Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8184731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:36:18+00:00 2026-06-07T01:36:18+00:00

I have to write a script which will mask the sensitive data in the

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:36:21+00:00Added an answer on June 7, 2026 at 1:36 am

    One way using awk. When found words phone, dob or pin at the beginning of the line (ignoring case) substitute in second field all characters but - with X. The print command is executed for every line.

    awk '
        BEGIN { 
            IGNORECASE = 1
        }
        $1 ~ /^(phone|dob|pin)$/ {
            gsub( /[^-]/, "X", $2 )
        }
        { print }
    ' $HOME_DIR/testdata.dat >$HOME_DIR/testdataupd.dat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a script which will be hosted on differents domains. This
Have been trying to write an awk script which processes a log file, but
I have to write the shell script, which will run on cygwin and build
i'm trying to write a script which would process certain files. The data are
I'm trying to write a basic script which creates a UI. I have reduced
I have to write a Matlab script that does this: The input is 2
I want to write a shell script which will find the occurence of multiple
I am trying to write a ruby script which will look in a directory
I am trying to write an php twitter script which will be run by
I want to write a PHP script which will first detect URL's and see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.