删除特定字符串后的所有内容 [英] Remove everything after a certain string

查看:48
本文介绍了删除特定字符串后的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我虽然这将是一个简单的任务,但是我遇到了一些麻烦.

I though this was going to be a simple task but I am having some trouble with it.

样本输入

$ cat file.txt
Brown Potatoes with Cheese
Yellow Potatoes with Sugar and Cheese

我想使用 sed 删除字符串 with

所以输出应该是

Brown Potatoes 
Yellow Potatoes 

我已经尝试过此正则表达式,但似乎不起作用.

I've tried this regex but it doesn't seem to work.

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:~$

这篇关于删除特定字符串后的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆