user3369729
user3369729

Reputation: 43

append text to an output from command line

I am looking to run this command

asterisk -rx "core show calls" | grep "active" | cut -d' ' -f1

it will output a number but I want it to append a "0:" at the beginning so the output looks like this

0:{output from command}

any ideas?

Upvotes: 3

Views: 13408

Answers (3)

iruvar
iruvar

Reputation: 23394

roll it all into

asterisk -rx "core show calls" | awk '/active/{print "0:"$1}'

Upvotes: 3

Kostanos
Kostanos

Reputation: 10434

By using sed on the end:

asterisk -rx "core show calls" | grep "active" | cut -d' ' -f1 | sed 's/^/0:/g'

by ^ in regular expression you indicate to put 0: in the beginning. You can add any text this way. Also you can add it in any other place inside a string, not only in the beginning.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799430

echo -n "0:" ; asterisk ......

Upvotes: 7

Related Questions