Thanks PL,
I tried executing the sed command you gave and below is the result I get:
Input File
$ cat input.file
Value1
Value2
server1/mylogin,mypasswd
Value3
Value4
Code
$ cat editfile.test
#! /bin/ksh
line_no=1;
mask_text="SERVER/USERNAME,PASSWORD"
while read line
do
case $line_no in
1) var1=$line;;
2) var2=$line;;
3)
logon_var=$line
#YOUR CODE
sed "s#server1/mylogin,mypasswd#$mask_text#" input.file [I WANT TO USE $line INSTEAD OF server1/mylogin,mypasswd]
;;
4) var3=$line;;
5) var4=$line;;
esac
line_no=`expr $line_no + 1`
done < input.file
echo $logon_var
Output
$ ./editfile.test
Value1
Value2
$mask_text
Value3
Value4
server1/mylogin,mypasswd [This line is the result of the echo command]
Input file after execution
$ cat input.file
Value1
Value2
server1/mylogin,mypasswd [NO CHANGE, But I want this Changed]
Value3
Value4
Now adding -i flag in the sed, this time I used the same code above except for the sed line for which I used the below:
#YOUR CODE
sed -i "s#server1/mylogin,mypasswd#$mask_text#" input.file
Output
$ ./editfile.test
sed: Not a recognized flag: 1 [NOT SURE WHY GOT THESE, I AM USING KSH]
Usage: sed [-n] Script [File ...]
sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
server1/mylogin,mypasswd [This line is the result of the echo command]
Input file after execution
$ cat input.file
Value1
Value2
server1/mylogin,mypasswd [NO CHANGE, But I want this Changed]
Value3
Value4
Please help!!
---------- Post updated 05-14-10 at 12:03 AM ---------- Previous update was 05-13-10 at 11:49 PM ----------
Got it to work by using the following code:
perl -p -i -e "s!$line!$mask_text!g" input.file
Not sure if there is any other effective way!
Anyway thanks all for your inputs! its always learning with UNIX.COM :)