Discussion:
File - sed1line.txt
'Ruud H.G. van Tol' rvtol@isolution.nl [sed-users]
2016-07-01 14:38:36 UTC
Permalink
# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
sed 's/^[ \t]*//' # see note on '\t' at end of file
# delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//' # see note on '\t' at end of file
# delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'
The '*' should be "1 or more" instead.

Now it matches every line,
including the ones without whitespace at either end.

Also, removing whitespace from the end first,
generally leaves less characters to move.

sed 's/^[ \t][ \t]*//'

sed 's/[ \t]*[ \t]$//'

sed 's/[ \t]*[ \t]$//;s/^[ \t][ \t]*//'


(yeah, benchmark-food)

-- Greetings, Ruud

Loading...