简体   繁体   中英

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?

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

roll it all into

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM