Masking of number

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Masking of number
# 1  
Old 01-27-2010
Masking of number

Code:
 
BAT:0310:2009-08-0:Y4   :H:D:00003721:03103721.IFH:00138770:05767:00000000001279'
EXR:CLP:912.570000'
STA:A:9071559:2009-08-10::Wer::Mrs'
DEF::531.97:531.97:310221661617::+ABC:BAL:1:N::::5:40.00:0.00:2009-08-10:CN:1111111111109962::3:N:missc :N:PH:00010833:
0001+ABC:FPT:4:N::::5:19.99:0.00:2009-08-10:CN:1111 1111 1111 9621::3:N:miss c ross:N:AI:00220600:S3IA'
VDI:2004-03-12:133030431725:4:M:00001912:AT:BSP:9124029676:2004-05-06:Parker:4:12:::::I:::::N::129.00:129.00
:1234567887234567678:0:155.40::6:::::+TAX:UB:6.30+TAX:XT:15.10'
CTR:2009-08-10:0.00:0.00:30.00:30.00:7819.00:7819.00'
GTR:11.50:0.00:0.00:28457.81:149449.38:21298.48:154882.82:1725.89'
TRA'

I have a txt file as above and i need to mask the middle digits of the credit card num such that only the first 6
and last 4 are visible.
The credit card number appear in 12th position in +ABC segment separted by :
( the 12th position can have other things also apart from the credit card which shouldn't be masked) the way to
identify credit card num is the field before it that is the 11 field in ABC section is having any of these values
TXE,AF,XT,TT,IT,TX,DX,TY,DT,MO,SE,CF,AXE,DF,CX,TF,DE,XF,CNE,IX,CN,SC,XTE,AX,CX
then credit card is in 12th position and needs to masked
The credit card can be of varying digits (16, 17, 19.........) and they can digits of credit card can appear
together or with space

The credit card number also appear in 26th position in VDI segment separated by :



I got quite a handful solution in the Unix forum but not exactly what i required the code was as below

Code:
awk -F'\+ABC' '{print$1}NF>1{for (i=2;i<=NF;i++)print $i}' OFS=':' |
awk -F: '{if ($27)print $27; else if ($12 ~ /^TXE$|^AF$|^XT$|^TT$|^IT$|^TX$|^DX$|^TY$|^DT$|^MO$|^SE$|^CF$|^AXE$|^DF$|^CX$|^TF$|^DE$|^XF$|^CNE$|^IX$|^CN$|^SC$|^XTE$|^AX$|^CX$/) print $13}' |
awk -F "" '{j=0; for(i=1;i<7+j;i++)if($i==" ")j++; for(;i<=(NF-4);i++)$i="*"}1' OFS=""



i am looking for the replacement in the input file itself such that
the script once run should replace with * in the input file, the above code is giving me separate output and only the masked card number only,

i need the whole file as output with only the cc num being masked.

please advice
Thanks in Advance!!
# 2  
Old 01-27-2010
If you need get the file to be updated directly, you need think by sed -i or perl -i.

but why not use exist awk to output to new file, then rename it back?
# 3  
Old 01-27-2010
Hi rdc,

The last line of above is not giving me the desired output for cc num
with spaces, the above code is also throwing some syntax error

Thx a lot
# 4  
Old 01-27-2010
what is the format that you have for the credit card number and are the below format available:

meaning is it possible that exist 2 spaces only ?
Code:
11111111 1111 9621

because I have wrote a script that applicable with 3 spaces and no spaces format only.

BR


---------- Post updated at 15:02 ---------- Previous update was at 14:55 ----------

I mean is the first space after the first 4 digits exist or not?

Note:- there is no problem if there are no spaces.

---------- Post updated at 15:30 ---------- Previous update was at 15:02 ----------

kindly note that the position that you mentioned earlier are not the 11 && 12 fields but they are the 12 && 13 fields

use below
use nawk , gawk or /usr/xpg4/bin/awk



Code:
nawk '
($12 ~ /TXE|AF|XT|TT|IT|TX|DX|TY|DT|MO|SE|CF|AXE|DF|CX|TF|DE|XF|CNE|IX|CN|SC|XTE|AX|CX/)
{
m=match($13," ")
x=length($13)
             if (m) {
                         s=substr($13,1,7)
                         b=substr($13,x-3)
                        for (i=8;i<x-3;i++) {stars=stars"*"}
                     }
             else {
                          s=substr($13,1,6)
                          b=substr($13,x-3)
                          for (i=7;i<x-3;i++) { stars=stars"*" }
                    }
    $13= s stars b
}
1' FS=":" OFS=":" infile.txt > outfile.txt

then you can rename the output file:-
mv outfile.txt  infile.txt

for the VDI pattern just change the above mention fields to the required one
and feed us back about the program above.


SmilieSmilieSmilie
# 5  
Old 03-05-2010
Appreciate ahmad.diab's solution
# 6  
Old 03-11-2010
Thanks for your appreciations. SmilieSmilieSmilie SmilieSmilieSmilie

did it work for you?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Masking Bank Account Number except last 4 digits in the file

Hello Unix Guru's, I need help in the masking Bank Account Number except last 4 digits in the file using either unix command or shell script. I'm greatly appreciate your help. File Name: Sample.txt 560|101012|4267||||||||520114025017|Balance_bank|06/30/2018||||151716.41|AUD... (13 Replies)
Discussion started by: Pradeep R
13 Replies

2. Shell Programming and Scripting

Masking with gsub command

My file "test.dat" data as below Requirement is to mask(replace) all english characters with "X" EXCEPT first 7 characters of every line. my command awk '{gsub("]","X")}1' test.dat looks not working properly, Appreciate any suggestion... (6 Replies)
Discussion started by: JSKOBS
6 Replies

3. UNIX for Dummies Questions & Answers

Masking data

How Can I mask one particular columns using some unix command? (4 Replies)
Discussion started by: dsa
4 Replies

4. Shell Programming and Scripting

Masking algorithm

I have a requirement of masking few specific fields in the UNIX file. The details are as following- File is fixed length file with each record of 250 charater length. 2 fields needs to be masked – the positions are 21:30 and 110:120 The character by character making needs to be done which... (5 Replies)
Discussion started by: n78298
5 Replies

5. Programming

Masking Password with *'s

So I've been working on this for some time now and can't seem to find the solution that works for me. I'm working in C/Unix. Basically, I want to take a user input and output something different. For example, I want to take a password and output *'s. In another instance, I want to take inputed... (35 Replies)
Discussion started by: bigdrock44
35 Replies

6. UNIX for Advanced & Expert Users

.htaccess redirect with masking

I am looking to forward the following with masking via my .htaccess file: www.mywebsite.com/origpage www.mywebsite.com/newpage I do not want to forward the entire site, just this one page with masking. Neither page has an extension. I am able to forward with .htaccess - but it does not mask the... (1 Reply)
Discussion started by: globalnerds
1 Replies

7. Shell Programming and Scripting

masking issue

Hi I am facing an issue with the below script which has the below line each field being separated with a tab. I need to mask the 8 and 7th field based on following conditions 1. 8th field is 16 in length and is numerics i will mask the middle 6 digits except the first 6 and last 4. input... (2 Replies)
Discussion started by: mad_man12
2 Replies

8. Shell Programming and Scripting

Data Masking

I have a pipe delimited file that I need to 'mask' to before loading to keep some data confidential. I need to maintain the first 4 bytes of certain columns and replace the remaining bytes with an 'x'. I would like to maintain spaces but it's not a requirement. Example, need to mask columns 2... (2 Replies)
Discussion started by: 1superdork
2 Replies

9. Shell Programming and Scripting

Masking Content of a String

Hello, I need to know that whether a content of a string can be hidden or masked inside a shell script. My Sample Code is given below <Code> #!/usr/bin/ksh Userid=test DB=temp Passwd=`java Decryption test` # The Above command will get the encryped password for "test" user id and store... (2 Replies)
Discussion started by: maxmave
2 Replies

10. IP Networking

IP Masking

Is it possible for a internal LAN to mask a IP e.g. i have a server ip running the intranet ip being 192.168.0.8 and i want to make that like www.intranet.com is this possible on a internal network ? (1 Reply)
Discussion started by: perleo
1 Replies
Login or Register to Ask a Question