How to remove leading whitespace from each line in a file

前端 未结 7 666
余生分开走
余生分开走 2020-12-12 19:29

I have a file that looks something like this:

for (i = 0; i < 100; i++)
    for (i = 0; i < 100; i++)
  for (i = 0; i < 100; i++)
       for (i = 0;         


        
7条回答
  •  既然无缘
    2020-12-12 20:05

    This Perl code edits your original file:

    perl -i -ne 's/^\s+//;print' file
    

    The next one makes a backup copy before editing the original file:

    perl -i.bak -ne 's/^\s+//;print' file
    

    Notice that Perl borrows heavily from sed (and AWK).

提交回复
热议问题