Linux删除指定字符串内容及以前的字符串内容以后的字符串内容(最新推荐)

服务器   发布日期:前天 07:33   浏览次数:108

内容编辑

[root@localhost ~]# cat a.txt
GeForce RTX 2080 Ti - 2733M
GeForce RTX 2080 Ti - 9282M
NVIDIA GeForce GTX 1080 Ti - 2947M
NVIDIA GeForce GTX 1080 Ti - 3098M

删除指定内容自身及以前所有的字符串内容

#原始内容
GeForce RTX 2080 Ti - 2733M
GeForce RTX 2080 Ti - 9282M
NVIDIA GeForce GTX 1080 Ti - 2947M
NVIDIA GeForce GTX 1080 Ti - 3098M

[root@localhost ~]# sed 's/.*GeForce //g' a.txt
RTX 2080 Ti - 2733M
RTX 2080 Ti - 9282M
GTX 1080 Ti - 2947M
GTX 1080 Ti - 3098M

删除指定内容以前所有的字符串内容不包括自身

#原始内容
GeForce RTX 2080 Ti - 2733M
GeForce RTX 2080 Ti - 9282M
NVIDIA GeForce GTX 1080 Ti - 2947M
NVIDIA GeForce GTX 1080 Ti - 3098M

[root@localhost ~]# sed 's/.*\(GeFo.*\)/\1/g' a.txt
GeForce RTX 2080 Ti - 2733M
GeForce RTX 2080 Ti - 9282M
GeForce GTX 1080 Ti - 2947M
GeForce GTX 1080 Ti - 3098M

删除指定内容自身及以后所有的字符串内容

#原始内容
GeForce RTX 2080 Ti - 2733M
GeForce RTX 2080 Ti - 9282M
NVIDIA GeForce GTX 1080 Ti - 2947M
NVIDIA GeForce GTX 1080 Ti - 3098M

[root@localhost ~]# sed 's/Ti -.*//g' a.txt
GeForce RTX 2080 
GeForce RTX 2080 
NVIDIA GeForce GTX 1080 
NVIDIA GeForce GTX 1080

删除指定内容以后所有的字符串内容不包括自身

#原始内容
GeForce RTX 2080 Ti - 2733M
GeForce RTX 2080 Ti - 9282M
NVIDIA GeForce GTX 1080 Ti - 2947M
NVIDIA GeForce GTX 1080 Ti - 3098M

[root@localhost ~]# sed 's/\(Ti\).*/\1/g' a.txt
GeForce RTX 2080 Ti
GeForce RTX 2080 Ti
NVIDIA GeForce GTX 1080 Ti
NVIDIA GeForce GTX 1080 Ti
原文地址:https://blog.csdn.net/liu_chen_yang/article/details/128932233

以上就是Linux删除指定字符串内容及以前的字符串内容以后的字符串内容(最新推荐)的详细内容,更多关于Linux删除指定字符串内容及以前的字符串内容以后的字符串内容(最新推荐)的资料请关注九品源码其它相关文章!