I want to delete last line of a file on a particular condition. I used sed and cut but they work only on the output stream but I want to do this in the file. Can someone help me? Thanks in advance.
sed -ie '$d' filename.txt
i
选项告诉sed
编辑文件。
I'll use a variant on another answer and suggest a simple use of ed:
ed tmp.tmp << EOC
$
d
w
q
EOC
Otherwise you can use sed/cut to a temporary file and mv
to overwrite the starting file.
You can always do:
cat * > out
Where you could remove 'cat *' with whatever you're doing, and the out is the result of that command.
I can take a more thorough look if you provide more information on what you're trying to do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.