search & replace password perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search & replace password perl script
# 1  
Old 03-24-2008
Bug search & replace password perl script

I wanted a perl script to be done for Password search & replace in two files.

For Example:

Example 1)--i am having a file such as
cat /opt/customer/Ariba/UAT/ariba/app/buyer/Server/config/Parameters.table

Example 2)--and i am having a other file in other location such as cat /opt/customer/home/username/CMStaging/UAT-20080304/AR/ServerFiles/opt/customer/Ariba/UAT/ariba/app/buyer/Server/config/Parameters.table

the example 1 file contains the string as **REPLACE**
the example 2 file contains the live password to be replaced.

i want is it should take the live password from the example 2 file & replace that (**REPLACE**)string with the example 1 file.

can anyone help me out for some code in detailed for the same on a urgent basis..

Thanks
Samir
# 2  
Old 03-24-2008
Searching for a string in file and replacing it could be done very easily with "sed", look at the forum base for various examples. Why you want this in perl ? You're gonna have to open the file, search / grep for string, then replace and close the file - uncecessary long.
# 3  
Old 03-24-2008
Perl can do this just like sed using perls inplace editor.

How do you find the "live password" in the second file?
# 4  
Old 03-25-2008
Bug search & replace script in shell or perl

actually i have 2 files
example

first file contains the live password in it & the second file contains **REPLACE** string

after running the script it should automatically take the password from the live file & replace that string of **REPLACE** in the second file

the same should be done for Multiple strings..

Please help...

Thanks
Samir
# 5  
Old 03-25-2008
You need to answer my question above and provide more details. The generic answer is get the password from the file it's in, search the other file for the pattern and replace it with the password:

s/\Q**REPLACE**\E/$password/;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search & Replace

Hi Gurus, I have two files. I want to read sessoin_name from the file1 and replace $Param4 & $Param5 in file2 with connection_name in specified in file1. The file1 will have data in following format File 1 session_name,connection_name s_abcd,Listener_2 s_def,Listener_1 source file... (7 Replies)
Discussion started by: r_t_1601
7 Replies

2. Shell Programming and Scripting

Search & Replace

Hi all Please can you help me with a script to check several files for the following string: encoding=""and replace it with: encoding="UTF-8"I did the following, : #!/bin/sh string1="encoding=""" string2="encoding="UTF-8" sed 's/'"$string1"'/'"$string2"'/g'but does not work. Please can... (18 Replies)
Discussion started by: fretagi
18 Replies

3. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

4. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

5. Shell Programming and Scripting

Perl script to search sprintf and replace with snprintf

Dear all, I am new to perl script and would need some help for my 1st script. I wrote a script to search sprintf(buf,"%s", sourcestring) and replace with snprintf(buf, sizeof(buf),"%s", sourcestring). As snprintf() requires an extra argument, so it is not a simple search-and-replace. I need to... (1 Reply)
Discussion started by: ChaMeN
1 Replies

6. UNIX for Dummies Questions & Answers

Search & Replace

Hi , I ahve a text file which has several instances of the text such as run_time: 09:30 I need to add double quotes before and after the time value i.e: run_time: "09:30" Any suggestions on how to go about the same (4 Replies)
Discussion started by: jobbyjoseph
4 Replies

7. UNIX for Dummies Questions & Answers

Perl search and replace not working in csh script

I am using perl to perform a search and replace. It works at the command line, but not in the csh shell script perl -pi -e 's@/Pattern@@g' $path/$file I used the @ as my delimiter because the pattern contains "/" (3 Replies)
Discussion started by: NobluesFDT
3 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. Shell Programming and Scripting

Search & replace

Is there any way we can achieve search & replace with awk? I could achieve the same with sed in following way - sed 's/A/B/g' file1 > file2 But the same regex if I try with using awk following way, awk 's/A/B/g' file1 > file2 it gives me Syntax error. I strongly believe I am... (1 Reply)
Discussion started by: videsh77
1 Replies

10. Shell Programming and Scripting

Using varible/varible substitution in Perl/sed Search & Replace

Hi, I have a program that searches for a particular string patten. I am however having difficulty passing the varible $i (in a loop) as the string pattern to replace. Using either perl or sed search and replace statements, I get the same kinda result. For example, using the perl: for i in... (3 Replies)
Discussion started by: Breen
3 Replies
Login or Register to Ask a Question