Linked Questions
18 questions linked to/from Is there a way to modify a file in-place?
3
votes
4
answers
1k
views
Not enough disk space: remove first n lines of text file without copying the file [duplicate]
I want to remove the first $rmv lines of a huge text file called $filename. This text file is so big that I cannot fit two copies of it on my hard drive.
The following leaves me with a blank file ...
442
votes
3
answers
230k
views
What are the shell's control and redirection operators?
I often see tutorials online that connect various commands with different symbols. For example:
command1 | command2
command1 & command2
command1 || command2
command1 && command2
...
174
votes
9
answers
59k
views
dd vs cat -- is dd still relevant these days?
I recently realized we can use cat as much as dd, and it's actually faster than dd
I know that dd was useful in dealing with tapes where block size actually mattered in correctness, not just ...
95
votes
7
answers
78k
views
How can I make iconv replace the input file with the converted output?
I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT.
Since adding the -o parameter ( in my experience ) actually writes ...
75
votes
10
answers
69k
views
How to obtain inverse behavior for `tail` and `head`?
Is there a way to head/tail a document and get the reverse output; because you don't know how many lines there are in a document?
I.e. I just want to get everything but the first 2 lines of foo.txt ...
42
votes
5
answers
60k
views
Delete the first n bytes of files
I've got an extreme problem, and all of the solutions I can imagine are complicated. According to my UNIX/Linux experience there must be an easy way.
I want to delete the first 31 bytes of each file ...
25
votes
6
answers
24k
views
Can I make `cut` change a file in place?
The man page doesn't give me much hope, but I'm hoping it's an undocumented (and/or GNU-specific) feature.
27
votes
4
answers
32k
views
How do I remove certain lines (using line numbers) in a file?
There are specific lines that I want to remove from a file. Let's say it's line 20-37 and then line 45. How would I do that without specifying the content of those lines?
10
votes
11
answers
12k
views
Is there a faster way to remove a line (given a line number) from a file?
A related question is here.
I often have to edit a large file by removing a few lines from the middle of it. I know which lines I wish to remove and I typically do the following:
sed "linenum1,...
12
votes
8
answers
13k
views
sed in-place line deletion on full filesystem?
Due to an application bug as yet undiagnosed, I have several hundred servers with a full disk. There is one file that has been filled up with duplicate lines—not a log file, but a user environment ...
4
votes
4
answers
6k
views
Is it possible to modify a file in a read only directory? [duplicate]
I have already read: Is there a way to modify a file in-place?
I am curious if there is a way to modify a file in place using a command that will not create temporary files.
Let's say I create a ...
12
votes
3
answers
1k
views
bash: Some issue when using read <<<"$VARIABLE" on a read-only root partition. Any known workarounds?
Just by coincidence I had to use my ATA-ID-to-device-name script (found here: https://serverfault.com/questions/244944/linux-ata-errors-translating-to-a-device-name/426561#426561) on a read-only / ...
2
votes
1
answer
4k
views
remove carriage return character from large binary file
I have a large binary file (nearly binary file !) which has many \r\n
in it [ gets Generated in windows env and doesn't have controle over generating application ]. I want to remove \r from this ...
4
votes
2
answers
5k
views
How to delete part of a binary file without copying
I need to delete the first 2 bytes of a 6MB file. However, this is an embedded Linux with only 32 Mbytes RAM and less than 1 MB free flash memory.
I tried using dd, as:
1 - # dd bs=1 skip=2 count=...
0
votes
2
answers
580
views
Why can't I overwrite a file with processed value?
This question prompted a thought I was not sure I understood well. I know that it is not possible or correct to use pipelines like cat myfile | grep -v mypattern > myfile due to how file handles ...