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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing search string with file name

Status
Not open for further replies.

billbose1

Programmer
Jul 10, 2007
8
US
Can somebody tell how to replace a string within a file by its filename.

Thanks in Advance.
 
I meant it removes the string and doesn't replace it with the filename (ARGV)
 
It shoud work.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Use single quotes. Using double quotes means that $ARGV is your shell's environment variable, not a Perl variable. I'm assuming Kevin and Miller are seeing something different because they're on Windows.
Code:
perl -p -i.bak -e 's/string/$ARGV/' filename
 
I tested on Windows.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Silly environment incompatibilities.
I play on windows. I work on linux.
This was play.

The also following work on windows:
Code:
perl -p -i.bak -e "s/string/$ARGV/" filename
perl -p -i.bak -e s/string/$ARGV/ filename

The following work on linux:
Code:
perl -p -i.bak -e s/string/\$ARGV/ filename
perl -p -i.bak -e "s/string/\$ARGV/" filename
perl -p -i.bak -e 's/string/$ARGV/' filename

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top