How to remove previous spaces before the start of the text without space + regex + sed +

How to remove previous spaces before 809in my output echo??

here is my example:

$ echo '   809 23/Dec/2008:19:20'
   809 23/Dec/2008:19:20
^^^3 spaces here preceding the 809    

I can remove 3 or 4 spaces with sed:

        ...4 spaces here   
$ echo '    809 23/Dec/2008:19:20' | sed 's/^.\{3\,4\}//'
809 23/Dec/2008:19:20
0 spaces here preceding the 809    

But I want my sed team to work on something more than 3

        .....5 spaces here
$ echo '     809 23/Dec/2008:19:20' | sed 's/^.\{3\,4\}//'
 809 23/Dec/2008:19:20
^1 spaces here preceding the 809    

Ho, am I writing my regular expression in sed to remove 3 or more spaces preceding 809?

+4
source share
4 answers

If you want to remove 3 or more spaces at startup, use

sed 's/^[[:blank:]]\{3,\}//'

More details

  • ^ - start of input
  • [[:blank:]]\{3,\} - 3 or more consecutive occurrences of any horizontal spaces.

3+ , , 809, :

sed 's/^[[:blank:]]\{3,\}809/809/'

:

sed 's/^[[:blank:]]\{3,\}\(809\)/\1/'

enter image description here

+6

xargs .

$ echo '   809 23/Dec/2008:19:20' | xargs
809 23/Dec/2008:19:20

xargs. . :

xargs , (         )

, , , ​​ . , xargs , , , , .

+3

, {minimum, maximum}. , , , . , "\ {3, \}". !

+1

:

$ echo '             809 23/Dec/2008:19:20' | sed -s 's/^ \{3,\}//'
809 23/Dec/2008:19:20
0

Source: https://habr.com/ru/post/1694021/


All Articles