[英]Using sed to match a pattern and deleting from the line to the end of the file
[英]Match pattern and append at the end of line using sed
我有一堆行例如:
hello.c
Untitled Folder
Shell.sh
Linux
等等
我想要的是追加/
在不包含的行的末尾.
使用sed。 即
hello.c
Untitled Folder/
Shell.sh
Linux/
有谁能够帮助我 ?
你可以使用一个地址:
sed -e '/\./!s=$=/='
这意味着:如果该行没有( !
)包含一个点( /\\./
),则追加/。
那样的东西?
files = ['hello.c', 'Untitled Folder', 'Shell.sh', 'Linux']
for i, f in enumerate(files):
if '.' not in f:
files[i] = "%s/" % f
print files
输出继电器:
['hello.c', 'Untitled Folder/', 'Shell.sh', 'Linux/']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.