sed/awk/python は、文字列一致後の文字間のすべてのスペースを置き換えます。

sed/awk/python は、文字列一致後の文字間のすべてのスペースを置き換えます。

最初の一致の後、文字間のすべてのスペースを削除したいと思います。例は次のとおりです。

exmpl 0 t h i s a r e t he spaces to d e l e t e
exmpl 1 m o r e spaces to d e l
exmpl 2 o r s m t h completely d i f f e r e n t
exmpl 12 y e t another l i n e

出力は次のようになります。

exmpl 0 thisarethespacestodelete
exmpl 1 morespacestodel
exmpl 2 orsmthcompletelydifferent
exmpl 12 yetanotherline

最初のテキストと数字の間、数字と後続のテキストの間のスペースもタブ文字にすることができます。

たとえば、sedの最初の部分と2番目の部分を一致させることができます。

sed -i 's/\(exmpl\s*[0-9]*\s*\)\(.*\)/\1\2/'

しかし、\ 2のすべてのスペースを削除する方法はわかりません。

ベストアンサー1

sedを使用してください:

sed -e 's/ //3g' file

exmpl 0 thisarethespacestodelete
exmpl 1 morespacestodel
exmpl 2 orsmthcompletelydifferent
exmpl 12 yetanotherline

3試合から交換

おすすめ記事