Quantcast
Channel: Adam Palmer, PHP Programmer, Website Security Consultant » Linux
Viewing all articles
Browse latest Browse all 15

BASH Script – Blank Out CC Details

$
0
0

Edit: I should have pointed out originally, as I have now received feedback on this. This is NOT the best or optimal way of performing this task. I was trying to illustrate as many shell scripting principles as possible in terms of ‘if’, ‘for’, counters, etc, and how such a one liner has been put together. Perhaps I should have thought of a better way of illustrating such principles, but nevertheless, here it is!

Here’s a quick one liner, can’t think why anyone would ever have any use for it, but maybe the principle itself could be of use to someone! This will take a file containing listings of 16 digit numbers, i.e. 1234123412341234 and replace it with XXXXXXXXXXXX1234

for I in ` cat mylist `; do P=”"; ctr=0; for I in `echo $I|grep -o .`; do let ctr=$ctr+1; if [ $ctr -gt 12 ]; then P=${P}${I}; else P=${P}”X”; fi; done; echo $P|tr -d ‘\n’; echo -ne “\n”; done

Duly spaced and indented:

for I in `cat mylist`; do

P=”"
ctr=0;
for I in `echo $I|grep -o .`; do

let ctr=$ctr+1;
if [ $ctr -gt 12 ]; then

P=${P}${I};

else

P=${P}”X”;

fi;

done;
echo $P|tr -d ‘\n’;
echo -ne “\n”;

done

Would love anyone to comment with variations.



Viewing all articles
Browse latest Browse all 15

Trending Articles