Pete Hamilton
Pete Hamilton

Reputation: 7910

Wrap STDIN with characters

I would like to turn "{something: here}" into "[{something: here}]"

For example:

$ echo "{something: here}" | magic_command
$ [{something: here}]

I want to do it all as part of a bash one liner using STDIN.

Seems simple enough. Any ideas? I'm drawing a blank :(

Upvotes: 1

Views: 932

Answers (3)

John Kugelman
John Kugelman

Reputation: 361685

Add one pair of brackets around everything:

echo "{something: here}" | echo "[$(cat)]"

Surround each line separately:

echo "{something: here}" | awk '{print "[" $0 "]"}'

Upvotes: 4

iruvar
iruvar

Reputation: 23364

in bash:

var="{something: here}"; 
printf "[%s]\n"  "$var"

Upvotes: 1

Alberto Zaccagni
Alberto Zaccagni

Reputation: 31560

You could try it with sed:

echo "{something: here}" | sed 's/\(.*\)/[\1]/'

Upvotes: 2

Related Questions