how to not-delete-a-file with some-command file.txt [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Can I make `cut` change a file in place?

    6 answers



  • What are the shell's control and redirection operators?

    3 answers



I've done this before, expect to mutate a file in place, something like $ tr 't' ',' <file.txt >file.txt and well, clearly the > redirection truncates the file before < can read it;



How do I mutate a file inplace without truncating/deleting it?







share|improve this question











marked as duplicate by Stephen Kitt, Timothy Martin, ThorSummoner, ilkkachu bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 6 at 20:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • <s>I didn't see anything about how to operate on-place with < > or <> operators in that question, thanks for the link! Very helpful, but I did not find a useful or equivalent question/answer there to my specific question :bow:</s> Specifically the answer unix.stackexchange.com/a/186126/61349 posted that there is basically no good way to do inplace mutations, either use a temporary file or a different file
    – ThorSummoner
    Jun 6 at 20:46







  • 2




    @ThorSummoner: You can't do what you are trying to do.
    – Jesse_b
    Jun 6 at 20:47






  • 2




    The second answer to that question should provide all the information you need.
    – Stephen Kitt
    Jun 6 at 20:47










  • argh, that one (Scott's answer there) is a good answer, but the question doesn't really indicate that subject at all...
    – ilkkachu
    Jun 6 at 20:49











  • also: Can I make cut change a file in place?, Modify a file without creating another file, Wait for stdout stream to finish and then add its contents to a file
    – ilkkachu
    Jun 6 at 20:51















up vote
0
down vote

favorite













This question already has an answer here:



  • Can I make `cut` change a file in place?

    6 answers



  • What are the shell's control and redirection operators?

    3 answers



I've done this before, expect to mutate a file in place, something like $ tr 't' ',' <file.txt >file.txt and well, clearly the > redirection truncates the file before < can read it;



How do I mutate a file inplace without truncating/deleting it?







share|improve this question











marked as duplicate by Stephen Kitt, Timothy Martin, ThorSummoner, ilkkachu bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 6 at 20:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • <s>I didn't see anything about how to operate on-place with < > or <> operators in that question, thanks for the link! Very helpful, but I did not find a useful or equivalent question/answer there to my specific question :bow:</s> Specifically the answer unix.stackexchange.com/a/186126/61349 posted that there is basically no good way to do inplace mutations, either use a temporary file or a different file
    – ThorSummoner
    Jun 6 at 20:46







  • 2




    @ThorSummoner: You can't do what you are trying to do.
    – Jesse_b
    Jun 6 at 20:47






  • 2




    The second answer to that question should provide all the information you need.
    – Stephen Kitt
    Jun 6 at 20:47










  • argh, that one (Scott's answer there) is a good answer, but the question doesn't really indicate that subject at all...
    – ilkkachu
    Jun 6 at 20:49











  • also: Can I make cut change a file in place?, Modify a file without creating another file, Wait for stdout stream to finish and then add its contents to a file
    – ilkkachu
    Jun 6 at 20:51













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Can I make `cut` change a file in place?

    6 answers



  • What are the shell's control and redirection operators?

    3 answers



I've done this before, expect to mutate a file in place, something like $ tr 't' ',' <file.txt >file.txt and well, clearly the > redirection truncates the file before < can read it;



How do I mutate a file inplace without truncating/deleting it?







share|improve this question












This question already has an answer here:



  • Can I make `cut` change a file in place?

    6 answers



  • What are the shell's control and redirection operators?

    3 answers



I've done this before, expect to mutate a file in place, something like $ tr 't' ',' <file.txt >file.txt and well, clearly the > redirection truncates the file before < can read it;



How do I mutate a file inplace without truncating/deleting it?





This question already has an answer here:



  • Can I make `cut` change a file in place?

    6 answers



  • What are the shell's control and redirection operators?

    3 answers









share|improve this question










share|improve this question




share|improve this question









asked Jun 6 at 20:39









ThorSummoner

1,08741327




1,08741327




marked as duplicate by Stephen Kitt, Timothy Martin, ThorSummoner, ilkkachu bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 6 at 20:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Stephen Kitt, Timothy Martin, ThorSummoner, ilkkachu bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 6 at 20:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • <s>I didn't see anything about how to operate on-place with < > or <> operators in that question, thanks for the link! Very helpful, but I did not find a useful or equivalent question/answer there to my specific question :bow:</s> Specifically the answer unix.stackexchange.com/a/186126/61349 posted that there is basically no good way to do inplace mutations, either use a temporary file or a different file
    – ThorSummoner
    Jun 6 at 20:46







  • 2




    @ThorSummoner: You can't do what you are trying to do.
    – Jesse_b
    Jun 6 at 20:47






  • 2




    The second answer to that question should provide all the information you need.
    – Stephen Kitt
    Jun 6 at 20:47










  • argh, that one (Scott's answer there) is a good answer, but the question doesn't really indicate that subject at all...
    – ilkkachu
    Jun 6 at 20:49











  • also: Can I make cut change a file in place?, Modify a file without creating another file, Wait for stdout stream to finish and then add its contents to a file
    – ilkkachu
    Jun 6 at 20:51

















  • <s>I didn't see anything about how to operate on-place with < > or <> operators in that question, thanks for the link! Very helpful, but I did not find a useful or equivalent question/answer there to my specific question :bow:</s> Specifically the answer unix.stackexchange.com/a/186126/61349 posted that there is basically no good way to do inplace mutations, either use a temporary file or a different file
    – ThorSummoner
    Jun 6 at 20:46







  • 2




    @ThorSummoner: You can't do what you are trying to do.
    – Jesse_b
    Jun 6 at 20:47






  • 2




    The second answer to that question should provide all the information you need.
    – Stephen Kitt
    Jun 6 at 20:47










  • argh, that one (Scott's answer there) is a good answer, but the question doesn't really indicate that subject at all...
    – ilkkachu
    Jun 6 at 20:49











  • also: Can I make cut change a file in place?, Modify a file without creating another file, Wait for stdout stream to finish and then add its contents to a file
    – ilkkachu
    Jun 6 at 20:51
















<s>I didn't see anything about how to operate on-place with < > or <> operators in that question, thanks for the link! Very helpful, but I did not find a useful or equivalent question/answer there to my specific question :bow:</s> Specifically the answer unix.stackexchange.com/a/186126/61349 posted that there is basically no good way to do inplace mutations, either use a temporary file or a different file
– ThorSummoner
Jun 6 at 20:46





<s>I didn't see anything about how to operate on-place with < > or <> operators in that question, thanks for the link! Very helpful, but I did not find a useful or equivalent question/answer there to my specific question :bow:</s> Specifically the answer unix.stackexchange.com/a/186126/61349 posted that there is basically no good way to do inplace mutations, either use a temporary file or a different file
– ThorSummoner
Jun 6 at 20:46





2




2




@ThorSummoner: You can't do what you are trying to do.
– Jesse_b
Jun 6 at 20:47




@ThorSummoner: You can't do what you are trying to do.
– Jesse_b
Jun 6 at 20:47




2




2




The second answer to that question should provide all the information you need.
– Stephen Kitt
Jun 6 at 20:47




The second answer to that question should provide all the information you need.
– Stephen Kitt
Jun 6 at 20:47












argh, that one (Scott's answer there) is a good answer, but the question doesn't really indicate that subject at all...
– ilkkachu
Jun 6 at 20:49





argh, that one (Scott's answer there) is a good answer, but the question doesn't really indicate that subject at all...
– ilkkachu
Jun 6 at 20:49













also: Can I make cut change a file in place?, Modify a file without creating another file, Wait for stdout stream to finish and then add its contents to a file
– ilkkachu
Jun 6 at 20:51





also: Can I make cut change a file in place?, Modify a file without creating another file, Wait for stdout stream to finish and then add its contents to a file
– ilkkachu
Jun 6 at 20:51











1 Answer
1






active

oldest

votes

















up vote
0
down vote













You cannot. The > redirect operator will create a new empty file as part of the pipeline. Tools (like sed --in-place) which appear to do so are creating a new file, writing to it, and moving the new file in place of the old one:



$ ls -i file; sed --in-place 's/foo/bar/' file; ls -i file
266110 file
262180 file





share|improve this answer





















  • yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
    – ThorSummoner
    Jun 6 at 20:57

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You cannot. The > redirect operator will create a new empty file as part of the pipeline. Tools (like sed --in-place) which appear to do so are creating a new file, writing to it, and moving the new file in place of the old one:



$ ls -i file; sed --in-place 's/foo/bar/' file; ls -i file
266110 file
262180 file





share|improve this answer





















  • yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
    – ThorSummoner
    Jun 6 at 20:57














up vote
0
down vote













You cannot. The > redirect operator will create a new empty file as part of the pipeline. Tools (like sed --in-place) which appear to do so are creating a new file, writing to it, and moving the new file in place of the old one:



$ ls -i file; sed --in-place 's/foo/bar/' file; ls -i file
266110 file
262180 file





share|improve this answer





















  • yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
    – ThorSummoner
    Jun 6 at 20:57












up vote
0
down vote










up vote
0
down vote









You cannot. The > redirect operator will create a new empty file as part of the pipeline. Tools (like sed --in-place) which appear to do so are creating a new file, writing to it, and moving the new file in place of the old one:



$ ls -i file; sed --in-place 's/foo/bar/' file; ls -i file
266110 file
262180 file





share|improve this answer













You cannot. The > redirect operator will create a new empty file as part of the pipeline. Tools (like sed --in-place) which appear to do so are creating a new file, writing to it, and moving the new file in place of the old one:



$ ls -i file; sed --in-place 's/foo/bar/' file; ls -i file
266110 file
262180 file






share|improve this answer













share|improve this answer



share|improve this answer











answered Jun 6 at 20:54









DopeGhoti

39.8k54779




39.8k54779











  • yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
    – ThorSummoner
    Jun 6 at 20:57
















  • yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
    – ThorSummoner
    Jun 6 at 20:57















yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
– ThorSummoner
Jun 6 at 20:57




yeah, in effect you will always need some kind of journal if you want to mutate the file contents in place, and it just so happens that if the working set fits in memory, and you have no power failures interruptions, you can get away with using the source file in memory as the effective journal :shrug: atleast thats how I put words to it
– ThorSummoner
Jun 6 at 20:57


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?