17 July 2011

remove leading whitespace with cat old.file | sed -e 's/^[ \t]*//' > new.file

from nixcraft
To remove all whitespace (including tabs) from left to first word, enter:

echo " This is a test" | sed -e 's/^[ \t]*//'

 

To delete trailing whitespace from end of each line, enter:

$ cat input.txt | sed 's/[ \t]*$//' > output.txt

 

Better remove all leading and trailing whitespace from end of each line:

$ cat input.txt | sed 's/^[ \t]*//;s/[ \t]*$//' > output.txt

No comments:

Post a Comment

Pages