Need to Mask Data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to Mask Data
# 8  
Old 08-16-2010
Code:
# cat infile
Unix|123|17-01-2010
UniX|124|17-01-2010
UnIx|125|17-01-2010
UNix|126|17-01-2010
UNIX|127|17-01-2010
UnIX|128|17-01-2010
unix|129|17-01-2010


Code:
# ./justdoit
Abcd|987|01-01-1999
Abcx|986|01-01-1999
Abid|985|01-01-1999
Ancd|984|01-01-1999
Anix|983|01-01-1999
Abix|982|01-01-1999
Ubcd|981|01-01-1999

Code:
# cat mask
A=a     a=A     1=9     01-01-1999
B=b     b=B     2=8
C=c     c=C     3=7
D=d     d=D     4=6
E=e     e=E     5=5
F=f     f=F     6=4
G=g     g=G     7=3
H=h     h=H     8=2
I=i     i=c     9=1
K=k     k=K
L=l     l=L
M=m     m=M
N=n     n=b
O=o     o=O
P=p     p=P
R=r     r=R
S=s     s=S
T=t     t=T
U=A     u=U
V=v     v=V
W=w     w=W
X=x     x=d
Y=y     y=Y
Z=z     z=Z


Code:
 
## justdoit ##
#!/bin/bash
 x=0
  while IFS="|" read -r name number date
   do
     cntn=$(printf "%s" "$name" | wc -c)
     cntnn=$(printf "%s" "$number" | wc -c)
     val=( "$name" "$number" )
     namenew="";numbernew=""
charstr=$(echo ${val[0]}|fold -w 1)
     for new in ${charstr}
      do
        if [[ $(echo "$new" | grep -o '[[:upper:]]') ]] ; then
            mynew=$(awk '{print $1}' mask | sed -n "/$new/p" | cut -d= -f2)
        else
            mynew=$(awk '{print $2}' mask | sed -n "/$new/p" | cut -d= -f2)
        fi
       namenew=$namenew$mynew
      done
      names[x]=$namenew
charnum=$(echo ${val[1]}|fold -w 1)
     for number in ${charnum}
      do
        mynumber=$(awk '{print $3}' mask | sed -n "s/$number=//p" )
        numbernew=$numbernew$mynumber
      done
      numbers[x]=$numbernew
      ((x++))
datenew=$(awk '{print $4}' mask)
   done<infile
 for ((i=0;i<${#numbers[@]};i++))
   do
    echo "${names[i]}|${numbers[i]}|$datenew"
   done

# 9  
Old 08-16-2010
Quote:
Originally Posted by ksmbabu
...
I fetch mask letter from another files.
...
Since the format of the other file has not been mentioned, I'll assume one of the simplest formats.

Here's a Perl script -

Code:
$
$
$ cat f3.mask
A=z
B=y
C=x
D=w
E=v
F=u
G=t
H=s
I=r
K=q
J=p
L=o
M=n
N=m
O=l
P=k
Q=j
R=i
S=h
T=g
U=f
V=e
W=d
X=c
Y=b
Z=a
a=Z
b=Y
c=X
d=W
e=V
f=U
g=T
h=S
i=R
k=Q
j=P
l=O
m=N
n=M
o=L
p=K
q=J
r=I
s=H
t=G
u=F
v=E
w=D
x=C
y=B
z=A
0=9
1=8
2=7
3=6
4=5
5=4
6=3
7=2
8=1
9=0
$
$ cat f3.data
Unix|123|17-01-2010
UniX|124|17-01-2010
UnIx|125|17-01-2010
UNix|126|17-01-2010
UNIX|127|17-01-2010
UnIX|128|17-01-2010
unix|129|17-01-2010
$
$
$ perl -lne 'if ($ARGV eq "f3.mask") {@x=split/=/; $y{$x[0]}=$x[1]}
             else {@z=split/\|/; $z[2]="01-01-1999"; $z[0]=~s/(.)/$y{$1}/g;
                   $z[1]=~s/(.)/$y{$1}/g; print join("|",@z)}
            ' f3.mask f3.data
fMRC|876|01-01-1999
fMRc|875|01-01-1999
fMrC|874|01-01-1999
fmRC|873|01-01-1999
fmrc|872|01-01-1999
fMrc|871|01-01-1999
FMRC|870|01-01-1999
$
$
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What is mask and effective right mask in setfacl?

Hi Guys, can someone explain what is mask and effective right mask in setfacl and getfacl command with example, unable to get it. (3 Replies)
Discussion started by: Jcpratap
3 Replies

2. Shell Programming and Scripting

Mask the Oracle Database Data

Hi, We have to mask the data that is coming from production environment to Non-production environment. The database is running in oracle platform. If anybody has generic scripts to achive this task,it would be great if that can be shared with me? Thank you, Jayaprakash. (10 Replies)
Discussion started by: bandaru_0810
10 Replies

3. Red Hat

Samba create mask and dir mask on RHEL 4.8

Hi Experts, I'm using samba -3.6.1 on Red Hat Enterprise Linux ES release 4 (Nahant Update 8) ,all seems ok. The issue im facing is as follows. When ever a user creates a file via windows explorer the permissions assgined to the file are as follows -rw-rwxr--+ 1 tom group2 0 Mar 9... (1 Reply)
Discussion started by: maverick_here
1 Replies

4. UNIX for Dummies Questions & Answers

How do mask off the string that match my value?

Hi, I have a file like following, aaabb aaavv bbdddaaab fgdgjhaa bfd 12352aa dgs1xaf sdgsdyg4 How can i get the output below(mask off all the line that have "a") by using vim #aaabb #aaavv #bbdddaaab #fgdgjhaa bfd #12352aa (4 Replies)
Discussion started by: 793589
4 Replies

5. UNIX for Dummies Questions & Answers

how to mask the password ?

Hi All, i am executing peoplesoft sqr command from unix prompt which has the unix id/password as parameter along with other parameters. i want to show whole command in log file but want to mask the id/password field. this command i am executing in shell script. Please suggest.. >sqr sqrname... (2 Replies)
Discussion started by: avi.coep
2 Replies

6. Shell Programming and Scripting

mask ID number

HP-UX 11i v2. #!/bin/sh Hi all. I have a flat file like this with lines like this: |07/19/07|08:26AM|1|CupsCoffee|CupsCo|989898989 |Doe, John Y |THE PLUS CARD - Price| | |Y| | 2.00| I would like to replace the id number (field 6) with a masked... (3 Replies)
Discussion started by: lyoncc
3 Replies

7. UNIX for Dummies Questions & Answers

overriding the mask in setfacl

hello everbody: Im trying to give the user "ydarwish" a full access over some directory on my sol9 machine. however the setfacl is recalculating the mask parameter keeping me from keeping him effective write and read access: root@Obi-Wan> setfacl -m u:ydarwish:rwx /IN_ARCHIVE6 root@Obi-Wan>... (4 Replies)
Discussion started by: aladdin
4 Replies

8. IP Networking

Changing the mask

What is the command to change the mask to 255.255.255.0 The system was set up incorectly and the mask needs to be corrected (1 Reply)
Discussion started by: kkinnon
1 Replies

9. Programming

password mask in C

Hi, Could any one help me to write a C program for password mask with ******. I mean whatever word i will type that will show on the screen as ***** and should store the correct value in a variable. Thanks in advance Krishna (5 Replies)
Discussion started by: krishna
5 Replies

10. IP Networking

Subnet mask

Hi, I have about 30 computers for users with subnet mask x.x.x.0, and 25 computers for workers with s.m. x.x.x.128. My server has a s.m. x.x.x.128 so with workers computers I can see my server and all the computers in that s.m., but I can't see the server from the users computers and I need to see... (7 Replies)
Discussion started by: Z0DiaC
7 Replies
Login or Register to Ask a Question