Summary of problem: You are never writing the data out to a file.
You read it from file.
You change it in scalar (memory).
You print to console.
Missing is the step to write it to an output file.
As noted by others, one approach is slurp-digest-spew (open, read to array, close, modify array, open for write, write, close. It is probably more efficient to perform the modifications as you read the data, which your script already does. This has the cost of increased risk of file corruption if power goes out during the spew phase, and it consumes more memory for the array. It has the advantage of being easy to write, and less disk space consumed.
Another approach is to write a temporary output file. open input, open output, read-process-write loop, close, close, rename or unlink input file (make sure rename works if you use that!), rename output file to input file. This has the advantage of reduced vulnerability to file corruption due to power failure at the cost of increased disk consumption. It does use less memory, as there is no array involved.
But the reason the file is unchanged when you cat it is because you didn't change it in your script. You only write the modified data to the screen.
In reply to Re: replace text
by marinersk
in thread replace text
by dawg31wh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |