Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
doneError:
./ne_script.ksh
sed: -e expression #1, char 27: unknown option to `s'Thanks!!
mk

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:

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.

![]() |
![]() |
![]() |

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