Making Changes without opening file

Hello,

I'm new to scripting, I have a file test.dat. I want to make changes to it with out openning it.

Example: test.dat has rows, and I want to change value "LA" to "TX" without opening it or without writing it to another file.

Is it possible?

Thanks

perl -pi -e "s/LA/TX/g;" test.dat

Cheers
ZB

Try this one sed 's/LA/TX/g' filename > filename1

request was not to write to another file,
your command redirects to filename1
in such a case you need to use the -i option available in GNU sed

(echo 'g/LA/TX/g'; echo 'wq') | ex -s filename
ruby -i -pe 'gsub(/LA/,"TX")' test.dat

:rolleyes:

I asked the same question last time ^O^. Its the easiest way to solve ur problem.

That should be

The original poster said "without writing it to another file." Your method does not solve his problem.

Not to be a nay-sayer here, but it is not possible to use any text or stream command on a file without first opening the the input file. The folks who gave you answers know this, and were smart to bypass this apparent requirement.

There is no way to get data out of a file without reading the data from disk. Period.

very true jim,

a closed file would remain unchanged,
though the solutions provided apparently first opens the file and then only proceeds executing.

i believe - opening a file - as the request means - physically opening it through any of the editor and modifying it - may be that one.

And identifying the list of datablocks pertaining to an inode and modifying could be another way.