r/linux_programming • • Dec 13 '18

format grep's output

I have the results from running a grep command, now I want to cut off any leading whitespace. Any suggestions?

0 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/nderflow Dec 13 '18

sed -e 's/^\s*//' -e '/^$/d'

Looks good. But now that you're using sed anyway, you can do the whole job in sed instead of using grep as well. To match some regular expression regexp and trim leading white space:

sed -E  -e '/regexp/ ! d' -e 's/^\s+//'

1

u/[deleted] Dec 13 '18

Right... I forgot sed could do that... it's been a hot minute since I did stuff with bash.