Computing.Net > Forums > Unix > replace cc numbers

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

replace cc numbers

Reply to Message Icon

Name: mike
Date: February 5, 2009 at 17:22:57 Pacific
OS: Solaris 9
Subcategory: Software Problems
Comment:

I have a customer who logged several cc numbers with apache. I need to replace them with x's. I tried the following, but the sed cmd is mangled and getting errors.

#!/usr/bin/ksh

for each in `ls | grep test1 | grep -v gz`;
do
cat $each | grep 'args=[0-9]\{16\}' > /dev/null
if [ $? -eq 0 ];
then
## Edit the line
sed -e 's/args=[0-9]\{16\}/args=X/\{16\}/g' $each > $each.tmp
mv $each.tmp $each
fi
done

Error:
./ne_script.ksh
sed: -e expression #1, char 27: unknown option to `s'

Thanks!!
mk



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 5, 2009 at 22:46:11 Pacific
Reply:

You have more than one problem.

First, you've designed your for loop to use a file.

ls | grep test1 | grep -v gz

The above line doesn't return a file name. It also returns the actual line matched with the filename. You need to include a -l flag with one of the greps above. Also, this is:

grep test1 *| grep -v gz

is more efficient if you want to include all the files in the working directory. if you insist on using ls, use -1 with it to make only one file at a time is listed

ls -1

(that's a 1 not a lower case L)

Second, I'm not certain what your data in the files looks like. I'm assuming it's something like this:

args=4\{16\}

You have to escape the slash in the sed command like such:

sed -e 's/args=[0-9]\\{16\\}/args=X\\{16\\}/g'

Finally, your use of a the for loop is an example of a Useless Use of Cat, UUOC. Read this link, and you might learn a few valuable shell scripting techniques:

http://partmaps.org/era/unix/award....


0

Response Number 2
Name: mkatnic
Date: February 6, 2009 at 08:03:00 Pacific
Reply:

Nails, while I can appreciate your condescending comments in an attempt to make yourself feel superior, it appears you are incorrect. Simply taking some of the logic out of the sed cmd did the trick, despite my horrible loop usage and lack of scripting knowledge.

However, for anyone else who might have the urge to assist, my customer also logged bank account numbers. The entries in the file will contain the string of "args=123456789&acctnum=123456789" and those values will be variable lengths.
Using sed -e 's/args=[0-9]\{16\} will find the 16 digit numeric values, but I'm not sure how to do it when the number of digits is not defined.

FWIW, I'm not trying to find the absolute most efficient way to do it, I just want to get these numbers cleaned up so I can move on to more important things.

Thanks in advance for any ideas you might have.


0

Response Number 3
Name: nails
Date: February 6, 2009 at 08:45:55 Pacific
Reply:

You've mistaken my love of Unix and Linux as condescension. Sorry if I hurt your feelings.


0

Response Number 4
Name: mkatnic
Date: February 6, 2009 at 11:06:24 Pacific
Reply:

No worries Nails. I'll manage.
My issue has been resolved.


0

Response Number 5
Name: lankrypt0
Date: February 9, 2009 at 12:55:16 Pacific
Reply:

GEEK DRAMA, NEWS AT 11!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: replace cc numbers

korn or unix www.computing.net/answers/unix/korn-or-unix/6382.html

Linux Internet Connection Red Hat 6.0 www.computing.net/answers/unix/linux-internet-connection-red-hat-60/727.html

overwrite the vaule in text file www.computing.net/answers/unix/overwrite-the-vaule-in-text-file/6142.html