Remove whitespace before text in a file in Linux bash

Home > Search
  by

Let's say file.txt has unpredictable whitespace before text.

   Hello
  World
       Hello
    World

 

The following sed command will eliminate the white space, so that all of the text is left justified.

~]# cat file.txt | sed 's/^[ \t]*//g'
Hello
World
Hello
World

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments