gpt4 book ai didi

linux - 用于替换换行符的 sed 命令在 solaris 中不起作用,但在 linux 中起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:38 25 4
gpt4 key购买 nike

我有以下 sed 命令在 linux box 中工作。但同样不适用于 solaris box。请纠正我是什么问题?

a=`sed ':a;N;$!ba;s/\n/ /g' file.txt`

throw ,

-bash-3.00$ a=`sed ':a;N;$!ba;s/\n/ /g' file.txt`
Label too long: :a;N;$!ba;s/\n/ /g

最佳答案

solaris 上使用 sed 你必须像这样分解它:

sed -e ':a' -e 'N;$!ba' -e 's/\n/ /g' file.txt

根据 man 页面:

b label  Branch to the : command bearing the label.
If label is empty, branch to the end of
the script. Labels are recognized unique
up to eight characters.

由于它们最多可识别八个字符,如果您的标签比您短,则需要将 sed 拆分为多个表达式。

关于linux - 用于替换换行符的 sed 命令在 solaris 中不起作用,但在 linux 中起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22189809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com