Delete whitespace in each begin of line of file, using bash

后端 未结 5 1194
迷失自我
迷失自我 2020-12-29 08:22

How i can delete whitespace in each line of file, using bash For instance, file1.txt. Before:

  gg g
 gg g
t  ttt

after:

gg         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 09:07

    To delete the white spaces before start of the line if the pattern matches. Use the following command. For example your foo.in has pattern like this

          This is a test                                
                        Lolll
                           blaahhh
          This is a testtt
    

    After issuing following command

    sed -e '/This/s/ *//' < foo.in > foo.out
    

    The foo.out will be

    This is a test
                 Lolll
                    blaahhh
    This is a testtt
    

提交回复
热议问题