Loading...

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

Answer #1 89.4 %

sed -i 's/ //g' your_file will do it, modifying the file inplace.

To delete only the whitespaces at the beginning of one single line, use sed -i 's/^ *//' your_file

In the first expression, we replace all spaces with nothing. In the second one, we replace at the beginning using the ^ keyword

Answer #2 94.4 %

tr(delete all whitespaces):

$ tr -d ' ' output.txt
$ mv output.txt input.txt

sed(delete leading whitespaces)

$ sed -i 's/^ *//' input.txt

You’ll also like:


© 2022 CodeForDev.com -