使用sed命令删除绝对路径 [英] remove absolute path using sed command
问题描述
我有包含以下方面像
文件 ABC ...
包括/home/user/file.txt
一些文本
我需要删除包括还完整路径包括之后。
我用下面的命令其中包括移除,但没有删除路径。
SED -i -r的###包括G'文件名
我也想了解上面的命令,但不明白以后的事(从某处复制粘贴)
I - 修改文件的变化
的R - 读取文件
S-需要输入
摹 - 需要输入
试试这个,
$ SED'/ ^包括/s/.*//g'file.txt的
ABC ...一些文本
据消除它与开始的行包括
所有文本。 取值
意味着替代品。所以取值/.*//摹
表示替换所有空的文本。先按g
意味着全球性的。替代将在全球范围内应用。
或
$ sed的'/ ^包括/ D'file.txt的
ABC ...
一些文本
D
表示删除。
它会删除它与开头的行包含
。要保存所做的修改(联编辑),你的命令应该是
SED -i'/ ^包括/s/.*//g'file.txt的
SED -i/ ^包括/ D'file.txt的
I have file which contain following context like
abc...
include /home/user/file.txt'
some text
I need to remove include and also complete path after include.
I have used following command which remove include but did not remove path.
sed -i -r 's#include##g' 'filename'
I am also trying to understand above command but did not understand following thing ( copy paste from somewhere)
i - modify file change
r - read file
s- Need input
g - Need input
Try this,
$ sed '/^include /s/.*//g' file.txt
abc...
some text
It remove all the texts in a line which starts with include
. s
means substitute. so s/.*//g
means replace all the texts with null.g
means global. The substitution will be applied globally.
OR
$ sed '/^include /d' file.txt
abc...
some text
d
means delete.
It deletes the line which starts with include
. To save the changes made(inline edit), your commands should be
sed -i '/^include /s/.*//g' file.txt
sed -i '/^include /d' file.txt
这篇关于使用sed命令删除绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!