2

我无法弄清楚如何使这项工作:

我有:

icon-braille icon-bookmark-empty icon-blogger icon-adult icon-address-book

而且我要:

'icon-braille','icon-bookmark-empty','icon-blogger','icon-adult','icon-address-book'

4

4 回答 4

2

这是OSX友好的sed "s/ /','/g;s/^/'/;s/$/'/"

$ echo "icon-braille icon-bookmark-empty" | sed "s/ /','/g;s/^/'/;s/$/'/" 
'icon-braille','icon-bookmark-empty'
于 2013-01-03T13:13:27.410 回答
1

使用 shell 和 sed:

echo "'"$(sed "s/ /','/g")"'"

例子:

$ echo "'"$(sed "s/ /','/g")"'"
icon-braille icon-bookmark-empty icon-blogger icon-adult icon-address-book
'icon-braille','icon-bookmark-empty','icon-blogger','icon-adult','icon-address-book'

第一行被插入,第二行——产生。

于 2013-01-03T13:11:10.243 回答
0
 $ echo "icon-braille icon-bookmark-empty icon-blogger icon-adult icon-address-book" | sed -e "s/ \+/','/g" -e "s/^/'/" -e "s/$/'/"
'icon-braille','icon-bookmark-empty','icon-blogger','icon-adult','icon-address-book'
于 2013-01-03T13:14:13.497 回答
0

您可以只使用外壳(假设是 bash)

$ list="icon-braille icon-bookmark-empty icon-blogger icon-adult icon-address-book"
$ result=""; sep=""
$ for word in $list; do result+=$sep\'$word\'; sep=,; done
$ echo "$result"
'icon-braille','icon-bookmark-empty','icon-blogger','icon-adult','icon-address-book'
于 2013-01-03T15:03:32.010 回答