[英]Match pattern and append at the end of line using sed
I have a bunch of lines for example: 我有一堆行例如:
hello.c
Untitled Folder
Shell.sh
Linux
and so on 等等
what I want is to append /
at the end of lines which do not contain .
我想要的是追加/
在不包含的行的末尾.
using sed. 使用sed。 ie 即
hello.c
Untitled Folder/
Shell.sh
Linux/
Can anybody help me ? 有谁能够帮助我 ?
You can use an address: 你可以使用一个地址:
sed -e '/\./!s=$=/='
Which means: if the line does not ( !
) contain a dot ( /\\./
), append /. 这意味着:如果该行没有( !
)包含一个点( /\\./
),则追加/。
Something like that? 那样的东西?
files = ['hello.c', 'Untitled Folder', 'Shell.sh', 'Linux']
for i, f in enumerate(files):
if '.' not in f:
files[i] = "%s/" % f
print files
ouput: 输出继电器:
['hello.c', 'Untitled Folder/', 'Shell.sh', 'Linux/']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.