Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: how to modify the text in file

by dse (Novice)
on Jan 19, 2005 at 07:31 UTC ( [id://423296]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how to modify the text in file
in thread ho w to replace a occurence of string by other string

  1. First, you need to replace "\w\d+" with "\w+\d+". Otherwise, your regex is only going to match "x1.data" instead of "xxx1.data".
  2. Second, I assume you're using bash, sh, or a similar shell on a Unix box. When passing arguments using double-quotation marks, you need to escape any backslashes, dollar signs, and certain other characters. I recommend using single-quotation marks instead since most characters don't have to be escaped inside them.

Suggestion:

perl -npi.bak -e 's:(\w+\d+\.data):testname/$1:g' file1.txt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://423296]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found