This question already has answers here:
sed in-place flag that works both on Mac (BSD) and Linux
(13个答案)
两年前关闭。
我以为这是一个简单的任务,但我有一些麻烦。
样本输入
$ cat file.txt
Brown Potatoes with Cheese
Yellow Potatoes with Sugar and Cheese

我想使用sed删除字符串后面的所有内容
所以结果是
Brown Potatoes
Yellow Potatoes

我试过这种正则表达式,但似乎不起作用。
sed -i -e "s/with.*//g" file.txt

我哪里做错了?

最佳答案

mathb@Balu:~$ sed -i.bak 's/with.*//g' file.txt
mathb@Balu:~$ cat file.txt
Brown Potatoes

Yellow Potatoes
mathb@Balu:~$

08-26 23:06