substitution of varying digits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting substitution of varying digits
# 1  
Old 01-19-2010
substitution of varying digits

I had a requirement in which in need to pan(*) out digits except the first six visible, followed by six *, and rest
visible of a variable(input)

ex:
Input - 123456789012345
Output - 123456******345
ex:
Input - 1234567890123456
Output - 123456******3456

so i tried something like below and it worked.
Code:
if($length($(i+12))>=15)
   
  {sub(substr($(12+i),7,6),"******",$(12+i))}

But now the updated requirement is that I need only the first six and the last 4 to be visible and the
rest(will vary depending upon length of input) replaced by * for any
length greater or equal to 15.
Please Advice how to achieve the above.
# 2  
Old 01-19-2010
Something like this:

Code:
echo "1234567890000000000012345" | sed 's/\([0-9]\{6\}\)\(.*\)\([0-9]\{4\}\)/\1(\2)\3/' | awk -F"[()]" '{gsub(".","*",$2); print }' OFS=""

# 3  
Old 01-19-2010
hey Panyam,

Its you Again!!, thanks a lot!! but would require more

as the following change needs to be imbedded in this code

Code:
 
ls *.txt | while read file ; do
awk -F: '/\+ABC/{for(i=0;++i<NF;){if($i~/\+ABC/&&length($(i+12))>=15){sub(substr($(12+i),7,6),"******",$(12+i))}}}1' OFS=":" $file > "$file"_encrypted
mv  "$file"_encrypted $file
done

The above code is the requirement if u remember(by chance) was to look for ABC in the .txt fle and replace the 12 field
with the above requirement.

Last edited by mad_man12; 01-19-2010 at 11:22 AM..
# 4  
Old 01-19-2010
Code:
perl -lne '/(\d{6})(\d+)(\d{4})$/; print $1, "*" x length $2, $3' file

# 5  
Old 01-20-2010
Code:
$ echo "1234567890000000000012345"  |awk -F "" '{for (i=7;i<=(NF-4);i++) $i="*"}1' OFS=""
123456***************2345



---------- Post updated at 12:08 AM ---------- Previous update was at 12:01 AM ----------

provide sample of your txt file here, we give you one line solution.
# 6  
Old 01-22-2010
encryption credit num

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::Ward::Mrs'
 
DEF::531.97:531.97:310221661617::+ABC:BAL:1:N::::5:40.00:0.00:2009-08-10:CN:11627877495099621::3:N:missc :N:PH:00010833:
0001+ABC:FPT:4:N::::5:19.99:0.00:2009-08-10:CN:1162 7987 9509 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 :

Code:
eg
1162 7987 9509 9621
1162798795099621
1162 7987 9509 9621 1234
11627987950996211234

The output needs to be
Code:
1162 79********9621
116279******9621
1162 79*************1234
116279**********1234

i used the above code as posted in my above post but it didn't
have the functionality of varying digits and the 11th field check of ABC section.

Please Advice how to achieve the above.
# 7  
Old 01-22-2010
It is a seriously bad idea, not to mention unlawful in most countries to post peoples credit card details in a forum like this. I can see the data looks old but none the less you should sanitize the data first.I work for a credit card company and they do scour the web looking for posts by their employees. If they found me posting this I would be marched out the door.I am sure Mrs Ward and Miss Ross would be less than delighted to find this here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

Merge lines with varying characters

Hi, I have a large set of data (firewall logs) that I'm trying to summarize. I've been able to write a script to consolidate the ports, now am looking to conslidate even further, based on IP. Source Destination Type Port 192.168.5.108 192.168.11.12 TCP 1, 2, 3, 4, 5, 15 192.168.5.109... (6 Replies)
Discussion started by: umang2382
6 Replies

3. Shell Programming and Scripting

Paste files of varying lengths

I have three files of varying lengths and different number of columns. How can I paste all three with all columns aligned? File1 ---- 123 File2 ---- 234 345 678 File3 ---- 456 789 Output should look like: 123 234 456 345 789 (6 Replies)
Discussion started by: Un1xNewb1e
6 Replies

4. UNIX for Dummies Questions & Answers

Help with varying data

I have flat file in which the length of the a record is 1000 characters. the last field of the file range is from 951 to 1000. So currently i am getting the last field data to be less than 1000 characters ( from 951 to 1000 i see that the data varies from 10 to 50). So is there a way we can pad up... (18 Replies)
Discussion started by: akshay01987
18 Replies

5. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

6. Shell Programming and Scripting

Insert varying length spaces between words

Hey all, Fist post, so be kind... I have written an expect script which logs into a terminal and gathers several screens of information. Unfortunately the log file gives me all the special escape and control characters from the terminal. I am hoping to use a combination of shell scripting, sed,... (1 Reply)
Discussion started by: mpacer
1 Replies

7. Shell Programming and Scripting

How to check the varying file size

How to know a file is of fixed file or not over a span of time Actually my requirement is to check the size of the file in a specific directory for 60 seconds, and if it remains the same then I have to move to some other directory.Else I have to stop the execution. Request you to guide me in... (4 Replies)
Discussion started by: av_vinay
4 Replies

8. Shell Programming and Scripting

help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~$ for x in $(seq 00 10); do touch file_$x; done m@pyhead:~$ ls file*... (2 Replies)
Discussion started by: amadain
2 Replies

9. Shell Programming and Scripting

extract string from varying delimiter line

Hi I have lines like this a=1, b=2, c=3, a=1, d=4, e=5, b=225, I need to extract the b=nnn... value. I dont know how many other entries will be before and after it in each line. Ive tried a basic line like awk '/b=/, $NF ~ /,/ ' myfile.txt but I think that it doesnt care which comma it... (5 Replies)
Discussion started by: rebelbuttmunch
5 Replies

10. Shell Programming and Scripting

Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is: awk -v TYP="$1 $2 $3 $4 $5 $6" ' BEGIN { CTYP = split (TYP,TYPP," ") } ... (2 Replies)
Discussion started by: CarlosNC
2 Replies
Login or Register to Ask a Question