【发布时间】:2020-06-19 17:13:40
【问题描述】:
我正在尝试从文本文件中提取数字,并且一直在使用 SED 命令删除不需要的字符。但是,我无法删除杂散的撇号。
这是示例文本:
CLASSES SCORES
[u'Precipitate', u'Crystals', u'Other', u'Clear'] [0.8788071274757385, 0.050357233732938766, 0.038349077105522156, 0.03248654305934906]
这是想要的结果:
0.8788071274757385, 0.050357233732938766, 0.038349077105522156, 0.03248654305934906
这是我正在使用的代码:
echo running
sed -i '/^CLASSES/ d' ~/Desktop/testgcloud/results.txt
sed -i -e "s/Precipitate//g" -e "s/Other//g" -e "s/Crystals//g" -e "s/Clear//g" -e "s/u//g" ~/Desktop/testgcloud/results.txt
sed -i -e "s/\[//g" -e "s/\]//g" -e "s/\'//g" ~/Desktop/testgcloud/results.txt
echo finished running
这是代码的结果:
'', '', '', '' 0.8788071274757385, 0.050357233732938766, 0.038349077105522156, 0.03248654305934906
另外,有没有办法删除每行的前四个逗号?
【问题讨论】: