perl -pi.bak -e 's/manulation/modification/' file.txt
The -i.bak option will make a backup copy called file.txt.bak in case your regex goes disastrously wrong. | [reply] [d/l] [select] |
perl -pi.bak -e 's/manulation/modification/' file.txt
Actually that will change the first (and supposedly unique) occurrence of 'manulation' in every line: indeed this makes sense, because the OP's request is sloppy to begin with. Anyway, he stresses that the substitution he wants must take place in a "particalur line" and mentions Tie::File, although to the effect of not wanting to use it. Thus I suspect he really wants the substitution to happen on a given line. But then... editi: given by what? If by a line number, say the tenth, then it's easy; you just have to enhance the above to:
perl -pi.bak -e '$.==10 and s/manulation/modification/' file.txt
If it's something different, then you have to tell us. | [reply] [d/l] [select] |
monks
I have to use this in file manipulation
like,
open(FILE,"....") or die $!;
while(<FILE>)
{
//Here Change part has to come
}
close FILE
1)how to open a file like >+ or +<?.
2)how to modify with in this file in while loop
Thanks in advance
| [reply] [d/l] |
One way is to 'slurp' the file into an array (1 rec per element), then amend array, then re-write file.
There's a good example here (http://www.goldb.org/goldblog/CommentView.aspx?guid=a858e606-de5d-4378-b538-8d4738cd9438)
if I'm allowed to point to it ...
Cheers
Chris | [reply] |