开发者

Solaris awk Troubles

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 numb开发者_如何学运维er 1

Also, /usr/xpg4/bin/awk does not exist.


I think you need to be clearer on what you want to get. For me your awk line doesn't 'strip FIND ME out'

echo "* *[**FIND ME**](find me)*" | nawk -F '* *[**|**]' '{print $2}'
[

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 than gawk. So maybe a tool that's better suited to the job is in order.

echo "* *[**FIND ME**](find me)*" | sed -e"s/.*\* \*\[\*\*\(.[^*]*\)\*\*\].*/\1/"
FIND ME


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,

$ echo "$line" | nawk '{gsub(/.*\*\[\*\*|\*\*\].*/,"");print}'
FIND ME

or if you are using bash/ksh on Solaris,

$ line="${line#*\[\*\*}"
$ echo "${line%%\*\*\]*}"
FIND ME
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜