Why is sed putting substituted text at the start of a line?

后端 未结 1 1143
日久生厌
日久生厌 2021-01-25 08:02

On Mac OS X (bash), I\'m using the following sed at the command line:

$ sed \'s/\\(\\S*\\)/\\1 ~ /\' file1.txt > file2.txt

file1.txt

相关标签:
1条回答
  • 2021-01-25 08:11

    Pretty sure your sed does not understand \S to mean "non-whitespace". It's most likely trying to match "zero or more S characters", and it finds that match at the beginning of the string.

    You want to stick to the POSIX character classes:

    sed 's/[^[:blank:]]\+/& ~ /' file1.txt
    
    0 讨论(0)
提交回复
热议问题