Insert space after period using sed

前端 未结 4 1527
无人及你
无人及你 2021-01-21 14:19

I\'ve got a bunch of files that have sentences ending like this: \\@.Next sentence. I\'d like to insert a space after the period.

Not all occurrences of

相关标签:
4条回答
  • 2021-01-21 14:39

    The right command should be this:

    sed -i.bak -E "s/\\\@.(\S)/\\\@. \1/g" *.tex
    

    Whith it, you match any \@ followed by non whitespace (\S) and insert a whitespace (what is made by replacing the whole match with '\@ ' plus the the non whitespace just found).

    0 讨论(0)
  • 2021-01-21 14:50

    I think the following would be correct:

    s/\\@\.[^\s]/\\@. /g
    

    Only replace the expression if it is not followed by a space.

    0 讨论(0)
  • 2021-01-21 14:52

    Use this sed command:

    sed -i.bak -E 's/(\\@\.)([A-Z])/\1 \2/g' *.tex
    

    OR better:

    sed -i.bak -E 's/(\\@\.)([^ \t])/\1 \2/g' *.tex
    

    which will insert space if \@. is not followed by any white-space character (not just capital letter).

    0 讨论(0)
  • 2021-01-21 14:52

    This might work for you:

    sed -i .bak -E 's/\\@\. \?/\\@. /g' *.tex
    

    Explanation:

    If there's a space there replace it with a space, otherwise insert a space.

    0 讨论(0)
提交回复
热议问题