[英]sed command to replace newline character is not working in solaris but working in linux
我有以下sed命令在linux框中工作。 但同樣不適用於solaris盒子。 請糾正我的問題是什么?
a=`sed ':a;N;$!ba;s/\n/ /g' file.txt`
拋出,
-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
所需的標簽短。
在最初的sed
,我認為標簽本身必須在一條線上。 從我非常古老的sed & awk
Nutshell書中,它指出:
標簽是最多七個字符的任何序列。 標簽單獨放在一行並以冒號開頭:
:label
這意味着,您需要使用多個-e
參數將其與腳本的其余部分分開,或者查看Solaris框上是否有nawk
或gawk
。 或者,因為看起來你只想用空格替換所有換行符,所以有更好的工具,比如tr
,翻譯實用程序,它至少應該像sed
一樣無處不在:
a=`tr '\n' ' ' <file.txt`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.