find and replace with variable -sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find and replace with variable -sed
# 1  
Old 12-26-2012
find and replace with variable -sed

Hi,

I have a ksh script where I am trying to mask the password in the log files.

$loc - is my directory
$PGUIDE_DB_USER_PSW - is a variable that holds the password I am looking for

Code:
find $loc/logs -type f -exec sed -i "s/$PGUIDE_DB_USER_PSW/*****/"g {} \;

I get an error:

ksh: /*****/g: not found
sed: illegal option -- i


Any ideas?
# 2  
Old 12-26-2012
I am not a expert but i making a guess , the sed version you are using does not have -i option in it. I believe you are using a solaris machine.
# 3  
Old 12-26-2012
try also:
Code:
find $loc/logs -type f -exec sed -i 's?$PGUIDE_DB_USER_PSW?*****?g' {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/replace using variable

Hello everyone, In one of my shell script I am doing sed/replace using a variable to find a string in a file & replace it with another string in same file. The challenge which I am facing is that, the variable which I am using with "sed" is having one of character as "/" Here is below how... (4 Replies)
Discussion started by: gr8_usk
4 Replies

2. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

3. Shell Programming and Scripting

Find a variable in a file and replace its value

HI , I can't find a solution to the following: In a simple menu script I want to capture the input from the user with "read" and use it as a value in a variable Rempages="some_value" which is in a different script file. So I have to perform a search and replace for this variable and only... (4 Replies)
Discussion started by: svetoslav_sj
4 Replies

4. Shell Programming and Scripting

Replace with a variable in sed command

Hello, I have this command and it works fine. My question is that how can we replace the N by a variable, to print for instance a big number of lines. It means if I want 100 lines after an expression, to not put "N" 100 times in the sed. Code: $ sed -n '/aaa/{n;N;N;s///g;s/;/; /g;p;}'... (2 Replies)
Discussion started by: rany1
2 Replies

5. Shell Programming and Scripting

Find and replace with variable using sed or awk

hi, i have file say email.temp looks like Bell_BB 17 Bell_MONTHLY 888 SOLO_UNBEATABLE 721 and another file r3 Bell BB,Bell_BB Bell,Bell_MONTHLY SOLO,SOLO_UNBEATABLE i want email.temp files $1 say Bell_BB should be replaced by r3 Bell BB and Bell_MONTHLY by... (2 Replies)
Discussion started by: raghavendra.cse
2 Replies

6. UNIX for Dummies Questions & Answers

sed to replace text with a variable

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)
Discussion started by: orahi001
1 Replies

7. Shell Programming and Scripting

replace with value of variable using SED

Hello everyone, I need to replace a pattern with "value of a variable" using sed but no luck. i tried the below ABC=STR2 sed 's/STR1/$ABC/g' <file> (also tried \ , $ and " in combination but failed) Appreciate any help. Thanks Prvn (2 Replies)
Discussion started by: prvnrk
2 Replies

8. Shell Programming and Scripting

find and replace variable

Is there an easy way of doing this cat file1 jkasjhjgfg LTRIM(RTRIM(aa_bb_cde)) aragsfdg LTRIM(RTRIM(aa_bb_cde)) aregfafdgfg sdgsfdagdfg gadfg eafgsadgsa asdgsfdgag LTRIM(RTRIM(aa_bb_cde)) rfghsdfhd I want to replace each occurence of LTRIM(RTRIM($x)) with LENGTH(LTRIM(RTRIM($x)))=0... (4 Replies)
Discussion started by: alfredo123
4 Replies

9. Shell Programming and Scripting

Find and replace the value in a variable

I have a variable whose value is I="user1:x:1100:1200:ID for user1:/home/user1:/bin/ssh-dummy-shell" I want to replace the last part '/bin/ssh-dummy-shell' with '/bin/true' I tried using sed but it garbled sed 's/\/bin\/ssh-dummy-shell/\/bin\/true' $I Thanks for the help (5 Replies)
Discussion started by: aajmani
5 Replies

10. Shell Programming and Scripting

find and replace text with a variable?

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)
Discussion started by: doublejz
3 Replies
Login or Register to Ask a Question