Use sed to delete all leading/following blank spaces in a text file

后端 未结 4 1975
小蘑菇
小蘑菇 2020-12-16 02:04

File1:

  hello  
  world  

How would one delete the leading/trailing blank spaces within this file using sed - using one command (n

4条回答
  •  粉色の甜心
    2020-12-16 02:23

    perl -lape 's/^\s+|\s+$//g'
    

    Honestly, I know perl regexps the best, so I find perl -lape much easier to use than sed -e.

    Also, to answer the original question, you can have sed execute multiple operations like this:

    sed -e 's/something/something else/' -e 's/another substitution/another replacement/'
    

    Apparently you can also put the two substitutions in one string and separate them with a semicolon, as indicated in another answer.

提交回复
热议问题