I have a command which gives me output like:

total time take                           11.1464s

I would like to print it like:

total time take=11.1464s

How can this be done in a shell script?

  • @pLumo Be careful, the + is extended RegExp syntax which sed by default doesn't understand unless backslash-escaped or called via sed -r.
    – AdminBee
    Nov 14, 2019 at 7:58

2 Answers 2



... | sed 's/   */=/'


... | sed -E 's/  +/=/'

or if it's not spaces but a tab:

... | sed -E 's/ \t+/=/'

(this works in GNU sed, but may not work in all versions of sed)

  • Thanks , this solution worked for me.
    – Milan
    Nov 14, 2019 at 8:18
  • \+ is a GNUism. Actually, that last one perhaps be [ \t]{2,}, since there's no guarantee the first character is space either.
    – ilkkachu
    Nov 14, 2019 at 10:04

Piping whatever command displays that text through sed:

yourcommand | sed -r 's/ +([^ ]+)$/=\1/'

If it's a file:

sed -r 's/ +([^ ]+)$/=\1/' yourfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.