Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Find and replace with sed or awk

Original Message
Name: pnbalaji
Date: April 3, 2008 at 14:09:35 Pacific
Subject: Find and replace with sed or awk
OS: AIX 5.3
CPU/Ram: 8GB
Model/Manufacturer: IBM, 7026-H80
Comment:
Hi,

I have a problem in my requirement. I have a file called 1000.log which is basically an xml for an internet order at our site. The xml will contain a tag as given below.

<doc_no>5454545454545454</doc_no>

This doc_no field contains the unmasked credit card #. My requirement is to replace the characters between the first 6 and last 4 with spaces. After change, this line should be like as shown below.

<web_ordno>545454 5454</web_ordno>

The first 6 and the last 4 characters should be retained and the characters in between them should be replaced with spaces. Also, this should work for irrespective of the type of credit card.

For ex, visa card can be of 13 or 16 characters in length, AMEX card will be of 15 chars in length, Diner's club card will be of 14 chars in length.

Can some one help me?

Thanks,
Balaji.


Report Offensive Message For Removal

Response Number 1
Name: ghostdog
Date: April 3, 2008 at 19:21:47 Pacific
Subject: Find and replace with sed or awk
Reply: (edit)

awk '/<doc_no>/{
gsub(/<doc_no>|<\/doc_no>/,"");
l=length($0)
print "<doc_no>" substr($0,1,6)" "substr($0,l-4) "</doc_no>"
next
}1' file



Report Offensive Follow Up For Removal

Response Number 2
Name: pnbalaji
Date: April 7, 2008 at 13:16:28 Pacific
Subject: Find and replace with sed or awk
Reply: (edit)
Hi,

Thanks for your reply. However, I am having some problem with the code.

My code is given below.

=============================================
for stagedFile in $stagingDir/*.orders
do
echo "Processing $stagedFile.."
awk '/<\/doc_no>/ {
gsub(/<doc_no>|<\/doc_no>/,"");
print $0
l=length($0)
if ( l > 8 ) {
print "<doc_no>"substr($0,1,6)" "substr($0,l-4)"</doc_no>"
}
next
}1' $stagedFile
done
=============================================

Please see the sample output below.
=============================================
<pay_documents>

<doc_type>CC</doc_type>

Credit card # is 4060420233588945
and its length is 27
<doc_no> 8945</doc_no>
<doc_date>1005</doc_date>

</pay_documents>

=============================================

I displayed the credit card # just for debugging. There are couple of errors in this which I am listing below.

1. The length is shown as 27 though it is a 16 digit card #.
2. It loses the formatting of the XML. The lines in the xml are intended and after running this awk script, it loses the formatting.
3. It is displaying only the last 4 digits of the credit card where it is supposed to display the first 6 digits and last 4 digits of the card #.

I assume the card length is calculated by adding the leading spaces also. I tried to fix it, but could not.

Can you please help?

Thanks,
Balaji.


Report Offensive Follow Up For Removal

Response Number 3
Name: pnbalaji
Date: April 7, 2008 at 13:17:32 Pacific
Subject: Find and replace with sed or awk
Reply: (edit)
Just to clarify, it loses the formatting of the credit card line alone, not the entire xml.

Thanks,
Balaji.


Report Offensive Follow Up For Removal

Response Number 4
Name: ghostdog
Date: April 7, 2008 at 18:34:33 Pacific
Subject: Find and replace with sed or awk
Reply: (edit)
where is the part where you displayed the message ?? i didn't see it in your code.
My guess is that you displayed whole length of the record, not the credit card numbers.

Report Offensive Follow Up For Removal

Response Number 5
Name: pnbalaji
Date: April 8, 2008 at 06:31:52 Pacific
Subject: Find and replace with sed or awk
Reply: (edit)
I have this code in a script called ccmask.sh and I am executing as below.

ccmask.sh /met/le/ocs | tee test.log

I am getting the stagingDir as a command line parameter. The output that I pasted is from test.log. When I run the script, it displays the contents of all XMLS on the screen, which I am rewriting into a file called test.log using the tee command. If you can provide your email id, I can forward the original XML and the test.log file to you.

Hope this helps.

Thanks,
Balaji.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Find and replace with sed or awk

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC