Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文件foo.txt包含
foo.txt
12345 123 123456
如何制作一个sed将中间数字放在括号中的命令?
sed
所以看起来像
1(234)5 1(2)3 1(2345)6
sed 's/./&(/;s/.$/)&/' foo.txt
结果
这可能对您有用(GNU sed):
sed 's/\B.*\B/(&)/' file
perl -pe 's/(.)(.*?)(.)$/$1($2)$3/g' your_file