我试过这个命令,
grep '/static' dir/* | xargs sed -i 's/\/static//g'
Run Code Online (Sandbox Code Playgroud)
但我使用的sed版本不支持-i参数.
要将文件中的字符串替换为与输出相同的输入文件,我通常会这样做:
sed 's/\/static//g' filename.txt > new_filename.txt ; mv new_filename.txt filename.txt
Run Code Online (Sandbox Code Playgroud) 我正在尝试将(字符串)轮胎尺寸列表从最小到最大排序.
['285/30/18',
'285/30/19',
'235/40/17',
'315/25/19',
'275/30/19']
Run Code Online (Sandbox Code Playgroud)
应该排序为:
['235/40/17',
'285/30/18',
'315/25/19'
'275/30/19',
'285/30/19']
Run Code Online (Sandbox Code Playgroud)
我基本上必须从右边,中间然后左边开始排序.
到目前为止我所拥有的(冒泡排序):
# this sorts the first numbers on the right.
nums = list(ulst)
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if ulst[j].split('/')[2] < ulst[i].split('/')[2]:
ulst[j], ulst[i] = ulst[i], ulst[j]
Run Code Online (Sandbox Code Playgroud)
我现在必须对中间进行排序而不会弄乱右行的排序,然后对左行进行排序....
如何在不创建for/if嵌套混乱的情况下解决这个问题?