How to remove leading whitespace from each line in a file

awk, grep, sed, unix

Solution

sed "s/^[ \t]*//" -i youfile

Warning: this will overwrite the original file.

Problem

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; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) ``` I want it to look like this (remove indentations): ``` for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) ``` How can this be done (using `sed` maybe?)?

Original source