我有普通的BSD SED (非GNU)。这就是我要跑的东西。它在最后一个sed命令上失败了。错误是:字符串比8个字符长;标签N是无效的或类似的。这不是全部代码--只是失败的部分:
set -x
chg ()
{
file=$1
sed ":1
N
$!b1
s/)/,col1)/5 " $file > tmp && mv tmp $file
}
chg $f
sed: 0602-404 Function N cannot be parsed for both above and below我试过了
set -x
chg ()
{
file=$1
sed ': 1 \
N \
$!b1 \
s/)/,col1)/5' $file > tmp && mv tmp $file
}
chg $f相同的命令将在命令行中工作
sed ': 1 <enter>
N <enter> etc你怎么解决这个问题?我希望)的第五次出现被,col )所取代,
sed -e $':x\nN;$!bx\ns/)/,col1)/5'谢谢。1以上的班轮不起作用
由于某些原因,sed on-liners上的最后一点/5在AIX上从来不适合我。
输入
#more sdat
) from ( d , bd , c , d blah
someblah, blah ) as
somebla, lah )
as
(some other pos )
dada输出
sed -e ':x' -e 'N;$!bx' -e 's/)/,col1)/5' sdat
) from ( d , bd , c , d blah
someblah, blah ) as
somebla, lah )
as
(some other pos )
dada
<br>发布于 2016-02-17 14:18:53
我已成功地测试了下列项目:
function chg {
sed ':x
N
$!bx
s/)/,col1)/5 '
}注意,我用单引号替换了双引号,用x替换了标签x。另外,请注意,在bx之后不允许使用任何空间。
使用此脚本,以下输入产生如下输出:
(a)(b)
(c) (d) (e) (f) (g)输出:
(a)(b)
(c) (d) (e,col1) (f) (g)sed使用:
man sed | tail -n 1
BSD May 10, 2005 BSD附注:在bash中,sed命令可以转换为与BSD一起工作的一行程序,如下所示:
sed -e $':x\nN;$!bx\ns/)/,col1)/5'https://stackoverflow.com/questions/35448687
复制相似问题