or instead of using a temp file and having the added overhead of the cat command...
The "-i" flag is for editing the file "in place", meaning it does not print to stdout but changes the file directly.
"--in-place" is a misnomer. sed -i does not change the file directly. It creates a temp file into which it dumps its output and when it's done writing to the temp file it renames it.
Using cat also has the benefit of preserving the original file's inode, permissions, and ownership, all of which can be clobbered when a temp file is used and then renamed with mv.
There are also differences in the permissions required. renaming a temp file to the original file's name only requires write permission on the directory. While using cat to modify the contents of the original file requires write permission on the original file.
Quote:
Originally Posted by vgersh99
This is GNUism - only GNU sed supports '-i'
FreeBSD also supports it (and a -I which doesn't reset the line counter when multiple files are processed). But your point still stands, that the option is not available on most platforms.
I have a file output.txt. File looks like this
name1 10
name2 2
name3 5
I get a number n and I need to remove all lines which has number (after name) smaller or equal to n number.
After that I need to write lines from file and my output must be like this:
Output: 'name1 10'
Output: 'name2... (1 Reply)
Is there an easy way to remove the first line of a file so that the file:
aaron
benjamin
cecilia
daniel
elliot
fernando
would become
benjamin
cecilia
daniel
elliot
fernando (4 Replies)
Hi!!!
When I use vi editor my file looks like this:
aaa2: 123.45^M
aaa1: 11.34^M
aaa3:
aaa3: 15.56^M
How to remove only line 3 ???
Thanks!!! (7 Replies)
Hi ,guys. I have one question:
I want to write a script which removes a line with certain string from a file, for example
The name of the file is: "passwd", the contents of it is below:
*************************
...
brownj2:x:5000:
hynesp:x:5001:
leeb:x:5002
dioxna:x:5003
...
... (2 Replies)
Hi all, i have a text file similar to belowA1
A2
A3
B1 ... .... *** # first occurance
B1 ... .... *** # second occurance
B1 ... .... *** # third occurance My desired output is B1 ... .... *** # second occurance
B1 ... .... *** # third occurance I want to remove the first line that is after... (3 Replies)
hi sir,
i need help..how to remove last line of the each file
for example i have files a.txt ,b.txt and so on..i wanted to delete last list of each file..the patten not same for each file..any help?
thanks in advance (3 Replies)
Hi,
I need some help in removing the header (first line) and the trailer (last line) in a give file...
The data file actually comes in EBCDIC format and I converted it into ASCII..
Now I need to strip off the first line and the last line..
I think we can use sed to do something like this:... (2 Replies)
I need to remove every second and every third line from a file. My idea was to do it in two operations. First every third line, then every second line. The problem is that i can't find out how to do it. I tried to look for some sed oneliners, but couldn't find any.
Suggestions? (4 Replies)