User Tools

Site Tools


sed:remove_whitespace_from_a_file

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sed:remove_whitespace_from_a_file [2019/12/10 18:27] โ€“ petersed: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]*//' > output.txt 
-</code> 
- 
----- 
- 
- 
-===== Delete trailing whitespace from end of each line ===== 
- 
-<code bash> 
-cat input.txt | sed 's/[ \t]*$//' > output.txt 
-</code> 
- 
----- 
- 
-===== Remove leading and trailing whitespace from each line ===== 
- 
-<code bash> 
-cat input.txt | sed 's/^[ \t]*//;s/[ \t]*$//' > output.txt 
-</code> 
- 
- 
-====== Linux - SED - Remove all whitespace (including tabs) from beginning of string ====== 
- 
-<code bash> 
-echo "     This is a test" | sed -e 's/^[ \t]*//' 
-</code> 
- 
-result: 
- 
-<code bash> 
-This is a test 
-</code> 
- 
-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.1576002479.txt.gz ยท Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki