[英]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.