sed:remove_whitespace_from_a_file
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
sed:remove_whitespace_from_a_file [2019/12/10 18:30] โ [Remove all whitespace (including tabs) from beginning of string] peter | sed:remove_whitespace_from_a_file [2019/12/10 18:33] (current) โ removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== SED - Remove whitespace from a file ====== | ||
- | |||
- | ===== Delete whitespace from begin of each line ===== | ||
- | |||
- | <code bash> | ||
- | cat input.txt | 's/^[ \t]*//' | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | |||
- | ===== Delete trailing whitespace from end of each line ===== | ||
- | |||
- | <code bash> | ||
- | cat input.txt | sed 's/[ \t]*$//' | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Remove leading and trailing whitespace from each line ===== | ||
- | |||
- | <code bash> | ||
- | cat input.txt | sed 's/^[ \t]*//;s/[ \t]*$//' | ||
- | </ | ||
- | |||
- | |||
- | ----- | ||
- | |||
- | ===== Remove all whitespace (including tabs) from beginning of string ===== | ||
- | |||
- | <code bash> | ||
- | echo " | ||
- | </ | ||
- | |||
- | result: | ||
- | |||
- | <code bash> | ||
- | 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 | ||
- | |||
- | |||
- | ---- | ||
- | |||
sed/remove_whitespace_from_a_file.1576002649.txt.gz ยท Last modified: 2020/07/15 09:30 (external edit)