Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace a string with a variable in a file

Status
Not open for further replies.

tdelamater

Programmer
May 28, 2005
9
US
I want to search for a string in a file, and if found append a variable to that string.

Here is what I have.

Code:
$servername | perl -p -i.bak -e 's/^server\-name \=\.*$/server-name = $F[0]/i' $FILE_LOC

Where $servername is a variable read in from the user from ksh.

I am not fluent in perl, but have inherited this script.

Any help would be much appreciated.
 
So what's the problem, have you tested it? does it work?
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Problem is...

Lets say I set serverName = "foo". I can echo $serverName, but in the perl program above I get the error.. and this isn't exactly what it is because i'm not at work today to see.. "foo not found."

Here is where I am looking for problems...

1. Using parameters in perl

2. The replacement caluse in the s/// operator.

3. My use of Strings because notice how everything is in a literal single quoted String and I am using a variable...

My guess is the replacement clause, but havn't found exactly what I want in the various perl tutorials I've been searching through.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top