substitution of varying digits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting substitution of varying digits
# 8  
Old 01-23-2010
This might be better off as script, but it will do what you ask.

Code:
perl -pe 's/\n//g; s/\x27/\n/; s/^\s+//' infile | perl -F: -lane 'print $F[26] if /^VDI/; print $1 while ( /\+ABC(?::.*?){12}(.+?):/g )' | perl -lpe 's/\s+//g' | perl -lne '/(\d{6})(\d+)(\d{4})$/; print $1, "*" x length $2, $3'

# 9  
Old 01-23-2010
Try this modification to rdcwayx' code:
Code:
awk -F "" '{j=0; for(i=1;i<7+j;i++)if($i==" ")j++; for(;i<=(NF-4);i++)$i="*"}1' OFS="" infile

# 10  
Old 01-23-2010
awk script above produces this output, when run against the example data:

Code:
BAT:03********************************************************767:
000000*****279'

EXR:CL*********000'

STA:A:**************************Mrs'

DEF::5**************************************************************************************************************833:
0001+A*********************************************************************************************3IA'

VDI:20**************************************************************************************************9.00
:12345*****************************************************.10'

CTR:20*******************************************.00'

GTR:11********************************************************.89'
TRA'

DEF::5**************************************************************************************************************833:
0001+A*************************************************************************************************************3IA'

Here is what the perl I posted produces:

Code:
perl -pe 's/\n//g; s/\x27/\n/; s/^\s+//' infile | perl -F: -lane 'print $F[26] if
/^VDI/; print $1 while ( /\+ABC(?::.*?){12}(.+?):/g )' | perl -lpe 's/\s+//g' | perl -lne '/(\d{6})(\d+)(\d{4})$/; print $1, "*" x length $2, $3'

116278*******9621
116279******9629
123456*********7678

I'll post a script. This is getting too silly for a one-liner.
# 11  
Old 01-23-2010
Quote:
Originally Posted by deindorfer
awk script above produces this output, when run against the example data:
The awker was created for the original requirement and there it produces:
Code:
1162 79********9621
116279******9621
1162 79*************1234
116279**********1234

To get this this out of the revised specs, including the additional field code restriction for field 11, similar to your Perl, I ended up with something crazy like this :
Code:
awk -F: '{gsub(/\n/,"")}1' RS="\'" infile2 |
awk -F'\+ABC' '/^ *VDI:/{print$1}NF>1{for (i=2;i<=NF;i++)print $i}' OFS='\n' |
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=""

Output:
Code:
116278*******9621
1162 79********9621
123456*********7678

I am sure this can be further optimized Smilie
Anyone? Smilie

Last edited by Scrutinizer; 01-23-2010 at 07:45 PM..
# 12  
Old 01-24-2010
I created perl that produces the correct output and which scales forever, provided the requester has posted *ALL* the use cases, so awk away; but the problem IS solved --in perl....

It's solved in awk, too. y'all just have to golf it some more. really it should be a script at this point. Let's call it quits: we solved in two languages, yay us!! Smilie

Last edited by deindorfer; 01-24-2010 at 03:08 AM.. Reason: none
# 13  
Old 01-27-2010
Thanks Unix and Perl Gurus!!

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 as the masked card number only,

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

please advice
Thanks in Advance!!
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