I am trying to work out how I can ammend a log file to remove variable strings in order to remove confidential information which I cant pass on.
As an example I have used phone numbers. A large log file contains multiple lines containing something like the below
In the code above i have placed x's where the variable numbers will be that i need to change, these varible numbers i need to be able to anonymize/replace. Is there a way of doing this ? Note that the numbers will always start with a set prefix as the first 2/3 digits also.
I'm not sure I understand what you're trying to do. Do you have a file that contains a string a numbers on each input line that you want to change each digit in that string to an "x"? (Could there by hyphens, plus-signs, and/or parentheses in the string? If so, should they be changed too?)
Or do you have a file that contains a string of "x" characters that you want to change to a phone number?
Are all lines in the same format, or are there other lines in different formats that are not supposed to be modified?
Please show us sample input (source file and whatever defines the "set prefix") and the corresponding output you want to produce from those inputs.
Hi Don - the file contains numbers which need to be changed to x's.
There are different formatted lines however say if the line contained a 10 digit number and started with 078 this should be modified to x's this will then allow me to amend the prefix accordingly.
The code in my post is the output I want to obtain, the only difference between the source and output is where the x's are there are numbers.
For the sample output you showed us (with the output being 10 "x"s surrounded by angle brackets), the following should work with any version of sed that conforms to the standards:
This User Gave Thanks to Don Cragun For This Post:
If we are dealing only with 10 digit numbers lead by "078", that will work. If not, we need to know more to identify the digits to be replaced, like "the first angle bracketed number in the resp. line", or "the number following the 'start call' string"
Isolate the number pattern and place it inside the capturing group in red.
The red pattern can be just the current example if it would satisfy the phone number without matching any other unwanted parts.
It could be more specific as: 078(?:\d){7}
If you want to match, strictly, 078 followed by seven more digits.
Or, just \d{10} for any 10 digits.
Either way, you have flexibility since x x length($1) will convert whatever is matched into a length of x, accordingly.
Based on your example, it appears that there's only one occurrence of the phone number per line, therefore no attempt was done to match more than once per line.
Hello,
I have simple while and for loops in a shell script and I would like to replace some characters in COL2 when I run it. I am on ubuntu 14.04
while read COL1 COL2 COL3 COL4
do
name=$COL2
#cat $name | sed -i "s|_| |g" $name
for i in $COL3 $COL4
do
some codes ...... run $i b="$name"... (11 Replies)
Hi,
Wish to remove "DR-" from the string variable (var).
var="DR-SERVER1"
var=`echo $var | sed -e 's/DR-//g'`
echo "$var"
Expected Output:
However, I get the below error:
Can you please suggest. (4 Replies)
Can someone tell me how I can do this?
e.g:
a=$(echo -e wert trewt ertert ertert ertert erttert
erterte
rterter
tertertert
ert)
How do i replace the STRING with $a?
I try this:
sed -i 's/STRING/'"$a"'/g' filename.ext
but this don' t work (2 Replies)
Hi Fellows,
I am new to shell, please help we me out in this..
i have file which some lines like this..
$$param1='12-jan-2011'
$$param2='14-jan-2011'
$$param3='30-jan-2011'
.
.
.....so on..
I want to change $$param3 to '31-dec-2011'. i have variable which is storing(30-jan-2011 this... (1 Reply)
Hi,
I'm making a script that automaticaly set file size and path in xml file.
I tried with :
sed -i 's/BOOTPATH/TEST/g' file.xml
it works fine
but if I use a viriable :
sed -i 's/BOOTPATH/$bootpathf/g' file.xml
with this one, no change are made.
I don't understand why. If a make a ... (13 Replies)
I was trying to replace a string ( for eg - @@asterisk@@ to * ) in variable using
cat $INFILE | while read LINE
do
stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'`
stmt=$stmt' '$stmt1
stmt2=`echo $LINE`
STATEMENT=$STATEMENT' '$stmt2
done
echo 'Statement with sed -- > '... (5 Replies)
Hi,
i call my shell like:
my_shell "my project name"
my script:
#!/bin/bash -vx
projectname=$1
sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp
cp temp test_config_doxy
the following error occurres:
sed s/'PROJECT_NAME ... (2 Replies)
I am trying to replace the default home page for several mac user accounts, I wrote a script that will hunt the files down and replace them with a pre-configured set. The problem I am having is that the download destination path for the browser is hard coded into a .plist (text config file) file... (5 Replies)
I'm trying to replace text in a file with text from a variable
I have the following in my script, but its not working:
#!/bin/ksh
echo "Enter the path to load scripts"
read x
echo "updating the templates"
sed "s/CHANGE_ME_TO_LOAD_PATH/"$x"/g" LoadFiles.sh > LoadFiles2.sh
I thought... (1 Reply)
Is there a way that I can make the following work with using variables?
perl -pi -e 's#blah#hrm#ig' replacetext
but like this
var=blah
perl -pi -e 's#$var#hrm#ig' replacetext (3 Replies)