- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed - masking credit card numbers
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2008 01:25 PM
тАО11-10-2008 01:25 PM
I'm hoping someone can help me with a sed statement (or if sed is even appropriate for this). I have a bunch of log files that have credit card numbers in them, and I need to mask the credit card numbers. All the credit cards are 16 digits and start with a 4 or 5. I want to replace the middle 8 digits with an asterisk (*). I've tried a number of things, but haven't been able to get it to work. Can someone please help me out? Thanks for any help or pointers in the right direction.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2008 01:52 PM
тАО11-10-2008 01:52 PM
Re: sed - masking credit card numbers
I prefer Perl since it probably has the most robust regular expressions available:
# perl -pe 's/\b(45\d\d)(\d{8})(\d{4})\b/$1\*\*\*\*\*\*\*\*$3/g' file
This will look for 16-digit numbers beginning with "45" and bounded by word "boundry" (\b) characters (e.g. whitespace) on either end. A '\d' is any digit. We escape the "*" to avoid special meaning. The '{n}' is a shorthand for the number of repetitions.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2008 03:01 PM
тАО11-10-2008 03:01 PM
Re: sed - masking credit card numbers
useful if you provided a sample of the data
to be mutilated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2008 03:02 PM
тАО11-10-2008 03:02 PM
Solutionsed -e 's/\([45][0-9]\{3\}\)[0-9]\{8\}\([0-9]\{4\}\)/\1********\2/' file
This will replace any 16 digit string that starts with 4 or 5. Even if embedded in a longer digit string. If we need to disallow that, we can add delimiters at the beginning and end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2008 09:38 PM
тАО11-10-2008 09:38 PM
Re: sed - masking credit card numbers
With awk also you can do the same
awk '{ if (substr($0,1,2)=="45") printf "%s********%s\n",substr($0,1,4),substr($0,12,4) }'
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2008 09:45 PM
тАО11-10-2008 09:45 PM
Re: sed - masking credit card numbers
Or you can use this also
awk '{ if (substr($0,1,2)=="45") printf "%s********%s\n",substr($0,1,4),substr($0,12,4)
else print $0
}'
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 12:35 AM
тАО11-11-2008 12:35 AM
Re: sed - masking credit card numbers
Allow me to point out the obvious.
Credit card numbers should NEVER exist in clear text on a Unix or Linux system.
They should always be in a secure database, with encrypted access.
The fact you are even trying this scares the hell out of me.
Good luck with the sed command, you got good answers.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 04:24 AM
тАО11-11-2008 04:24 AM
Re: sed - masking credit card numbers
I wonder about the legality of keeping credit card numbers in plain text.
Do a google search and you'll find plenty of information regarding the legal requirements for storing different types of data....the complexity of the information is huge.
To make your life easier contact your Storage Manager and your companies legal department for guidance on how you should store the credit card information.
Without knowing your architecture I have to assume you're not in a good legal position right now.
Regards
Noticed in your profile you're in the US.
Found this link which may assist you
http://www.cit.cornell.edu/security/requirements/secreqs-confidentialdata.html
In that link is another link to https://www.pcisecuritystandards.org/
They look like good starting points to find out your legal requirements for storing the credit card data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 05:17 AM
тАО11-11-2008 05:17 AM
Re: sed - masking credit card numbers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2018 12:43 PM
тАО10-02-2018 12:43 PM
Re: sed - masking credit card numbers
HOW TO RESTRICT ONLY 16 DIGITS AND ONLY number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2018 01:45 PM
тАО10-02-2018 01:45 PM
Re: sed - masking credit card numbers
Please assist me in regex to mask middle 8 digits of 16 digits card number in linux? Any one can help on this will be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2018 10:43 PM - edited тАО10-08-2018 10:44 PM
тАО10-08-2018 10:43 PM - edited тАО10-08-2018 10:44 PM
Re: sed - masking credit card numbers
@FAZILUDDIN> regex to mask middle 8 digits of 16 digits card number
Assuming you have already extracted the number or only strings with >= 16 digits are credit card numbers.
This is similar to my reply to:
sed -e 's/\([0-9]\{4\}\)[0-9]\{8\}\([0-9]\{4\}\)/\1********\2/' file
Keeps first and last 4. Replaces middle 8 by "*".