Solaris awk 问题
我正在编写一个 shell 脚本,我需要从类似这样的内容中删除“FIND ME”:
* *[**FIND ME**](find me)*
并将其分配给一个数组。我让代码完美地工作..直到我将 Solaris 中的脚本移动到非全局区域。这是我之前使用的代码:
objectArray[$i]=`echo $line | nawk -F '*[**|**]' '{print $2}'`
现在打印:
awk: syntax error near line 1
awk: bailing out near line 1
建议我使用 nawk 尝试相同的命令,但我现在收到此错误: 另外
nawk: illegal primary in regular expression `* *[**|**]` at `*[**|**]`
input record number 1
source line number 1
, /usr/xpg4/bin/awk
不存在。
I'm writing a shell script and I need to strip FIND ME out of something like this:
* *[**FIND ME**](find me)*
and assign it to an array. I had the code working flawlessly .. until I moved the script in Solaris to a non-global zone. Here is the code I used before:
objectArray[$i]=`echo $line | nawk -F '*[**|**]' '{print $2}'`
Now Prints:
awk: syntax error near line 1
awk: bailing out near line 1
It was suggested that I try the same command with nawk, but I receive this error now instead:
nawk: illegal primary in regular expression `* *[**|**]` at `*[**|**]`
input record number 1
source line number 1
Also, /usr/xpg4/bin/awk
does not exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你需要更清楚自己想要得到什么。对我来说,你的 awk 行不会“删除 FIND ME ”,
所以如果你给出一些你期望的输入/输出的例子,这将会有所帮助。也许有办法用 sed 来做你想做的事?
编辑:
从评论中,您实际上想从行中选择“FIND ME”,而不是将其删除。
我猜这个
nawk
接受的正则表达式方言与gawk
不同。因此,也许需要一个更适合这项工作的工具。I think you need to be clearer on what you want to get. For me your awk line doesn't 'strip FIND ME out'
So it would help if you gave some examples of the input/output you are expecting. Maybe there's a way to do what you want with
sed
?EDIT:
From comments you actually want to select "FIND ME" from line, not strip it out.
I guess the dialect of regular expressions accepted by this
nawk
is different thangawk
. So maybe a tool that's better suited to the job is in order.像这样引用您的
$line
变量:"$line"
。如果仍然不起作用,您可以使用 nawk 执行另一种方法,因为您只想查找 FIND ME 的一个实例,或者如果您在 Solaris 上使用 bash/ksh,
quote your
$line
variable like this:"$line"
. If still doesn't work, you can do it another way with nawk, since you only want to find one instance of FIND ME,or if you are using bash/ksh on Solaris,