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

后端 未结 4 1986
小蘑菇
小蘑菇 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:42

    Note that in the more general case of applying several filters in a row to an input file without using intermediate files, the solution is to use pipes:

    sed -e 's/^[ \t]*//' a | sed -e 's/ *$//' > c
    

    Obviously they are not required here because one invocation of sed is sufficient, but if the second sed command was something different, like uniq or sort, then this pattern is the right one.

提交回复
热议问题