Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

asked on

Mask property values using bash and sed

Hi Experts,
pls refer this question. would like to extend bit further on masking the pwd values when we have more than one properties in a file.

https://www.experts-exchange.com/questions/29107089/Display-file-content-but-mask-password-value-in-bash.html
Solution from above question
cat /path/to/property//file|sed -e 's/db_password=.*/db_password=xxxxxxxxx/i'

Open in new window


could you pls help me how to mask two properties in single go please

hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=tiger
username_wls=weblogic
password_wls=welcome1
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

I assume db_passowrd=tiger should be db_password=tiger. Is that correct?
Avatar of enthuguy

ASKER

Sorry typo

Yes, you are correct :)
Why would you use cat to redundantly pipe to sed?  That line can be changed to remove the extraneous cat command.

sed -e 's/db_password=.*/db_password=xxxxxxxxx/i' /path/to/property//file

You can chain multiple cammands in sed.
sed -e 's/db_password=.*/db_password=xxxxxxxxx/i' -e 's/password_wls=.*/password_wls=xxxxxxxxx/i'  /path/to/property//file
ASKER CERTIFIED SOLUTION
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"Close Request Pending
enthuguy requested that this question be closed on 7/16/2018, as follows:
    enthuguy's comment #a42620693 (0 points)
For the following reason:
Thanks very much
To cancel this request, state your reason as a comment and click the 'Object' button."


I object to the above closure attempt, since it doesn't make much sense to be thanking experts while assigning points to one's own comment which wasn't even an answer.  I'm guessing this was a mistake.

You can chain multiple cammands in sed.
    sed -e 's/db_password=.*/db_password=xxxxxxxxx/i' -e 's/password_wls=.*/password_wls=xxxxxxxxx/i'  /path/to/property//file

True, serialband, and you can also do it without any '-e' switches like this:
    sed 's/db_password=.*/db_password=xxxxxxxxx/i; s/password_wls=.*/password_wls=xxxxxxxxx/i'  /path/to/property//file