Handling Parameters in Perl

Hi All,

I'm pretty new to the forum and also to UNIX. I have a requirement for which I need some help. I have a script (example.script) where I get user inputs using the read command. I would need to pass the read-fetched input to a perl command (explained below) in my script. The part which confuses me is that the input has characters like / and . which has to manipulated. Please help me on the same. Below are the files.

test.file: (Current)
--------

 
-
-
.LOGON SERVER/userid,password;
-
-

test.file: (Expected)
--------

 
-
-
.RUN FILE /home/user/my.test.logon;
-
-

example.script:
--------------

 
echo " Please enter the path to the LOGON file: \c"
read logon
 
perl -p -i -e "s/^\.LOGON.*$/.RUN FILE $logon;/g" test.file

I execute the example script as:

 
$ ksh example.script
 Please enter the path to the LOGON file: /home/user/my.test.logon

While running the above code, I am getting the below error message:

I hope this is because of using characters / and . in the input string without escape sequences (\). But basically I want input to be entered without escape characters, like in /home/user/my.test.logon, as it will be entered by all users. Is there a way in UNIX where I can have the input entered as-is and still I will be able to format the input before parsing it?

Any help on this is greatly appreciated.

Thanks in Advance. Let me know for any questions.

Dear Friend,

The test.file contain the following content
.LOGON SERVER/userid,password;

In the script file you should use the following perl code instead of your code

 
echo " Please enter the path to the LOGON file: \c"
read logon

perl -p -i -e "s!^\.LOGON.*!.RUN FILE $logon;!g" test.file

After run the command it will display the following
Please enter the path to the LOGON file: \c

Then give the input as like
/home/user/my.test.logon

Then see the test.file content. .It is contain the following content
.RUN FILE /home/user/my.test.logon;

Thanks a lot! Works like a Charm! So if we use (!) instead of (/) we do not want to escape characters like (/) and (.) ?

Please explain!

Refer the following link
perlre - Perl regular expressions