How to remove leading whitespace from each line in a file

前端 未结 7 668
余生分开走
余生分开走 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:21

    Use:

    sed -e **'s/^[ \t]*//'**  name_of_file_from_which_you_want_to_remove_space > 'name _file_where_you_want_to_store_output'
    

    For example:

    sed -e 's/^[ \t]*//'  file1.txt > output.txt
    

    Note:

    s/: Substitute command ~ replacement for pattern (^[ \t]*) on each addressed line

    ^[ \t]*: Search pattern ( ^ – start of the line; [ \t]* match one or more blank spaces including tab)

    //: Replace (delete) all matched patterns

    0 讨论(0)
提交回复
热议问题