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

后端 未结 5 1193
迷失自我
迷失自我 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:08

    "Whitespace" can include both spaces AND tabs. The solutions presented to date will only match and operate successfully on spaces; they will fail if the whitespace takes the form of a tab.

    The below has been tested on the OP's specimen data set with both spaces AND tabs, matching successfully & operating on both:

    sed 's/^[[:blank:]]*//g' yourFile
    

    After testing, supply the -i switch to sed to make the changes persistent-

提交回复
热议问题