====== SED - Delete - Delete BOTH leading and trailing whitespace from each line ====== sed 's/^[ \t]*//;s/[ \t]*$//' **NOTE:** Aligns all text flush left. **NOTE:** The expression '\t' is used to indicate a tab character (0x09) in the scripts. Some versions of sed do not recognize the '\t' abbreviation, so when typing these scripts from the command line, you should press the TAB key instead. '\t' is supported as a regular expression. ---- ===== Example ===== Running that command again this file: aaa bbb ccc returns: aaa bbb ccc ---- ===== Example ===== cat input.txt | sed 's/^[ \t]*//;s/[ \t]*$//' > output.txt ---- ===== Example - Remove all whitespace (including tabs) from beginning of string ===== echo " This is a test" | sed -e 's/^[ \t]*//' result: This is a test Where, * **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 pattern ----