删除文本文件中出现的字符串 [英] Remove occurrences of string in text file

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

问题描述

如何从文本文件(命令行)中删除特定字符串,例如

How would you remove a specific string from a text file (command line) e.g.

hello
goodbye
goodbye
hello
hello
hello
goodbye

在这种情况下,我想删除所有出现的再见"

In this case I would like to remove all occurrences of "goodbye"

Linux或Windows(只要linux命令在GNU中可用)

Either linux or Windows, (as longs as the linux command is available in GNU)

推荐答案

sed -i -e 's/goodbye//g' filename

要删除多个单词,请执行以下操作:

To delete multiple words:

sed -i -e 's/\(goodbye\|hello\|test\|download\)//g' filename

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

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