Solved

Solaris KSH fgrep

Posted on 2013-05-30
12
492 Views
Last Modified: 2013-05-31
greetings, in BASH, I have this piece of code:
ignore=$(xmllint --xpath "string(//*[local-name()='document']/*[local-name()='code']/@code)" ../Source/$core/$root/$xml)
if echo "${accept[*]}" | fgrep --word-regexp "$ignore"

Open in new window

...

the ignore variable stores a string.
I am checking to see if that string is in the array.
This works in BASH.

I am now forced to move to SOLARIS 10 with ksh.  --word-regexp is not available.
How do I see if the value is in the array in ksh?

Thanks.
0
Comment
Question by:Evan Cutler
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 39209753
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 39209781
ok...I'm interested...how do I use egrep on an array?  The example shown on the page is for a file.  THanks
0
 
LVL 77

Expert Comment

by:arnold
ID: 39209793
What is the output from echo?


Looping through the array might be what you have to do to compare each element
What is the content of ignore.
Egrep can do pattern matching,
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 9

Author Comment

by:Evan Cutler
ID: 39209806
well the echo returns a five digit string.  say abcde
if my array has four elements to it,
I need to know if abcde is one of the items in the array.
0
 
LVL 77

Expert Comment

by:arnold
ID: 39209833
What is the format of ignore?
If you can rearrange it as "(entry|entry2)"
echo entry |egrep "(entry|entry2)"

do you have an option to use perl instead?
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 39209836
ignore is a standard variable holding a string.  The xmllint output loads a five-digit string into the variable.

I have an array called "accept" and it's pre-loaded with a series of five-digit strings.
I need to know if $ignore is any one of the strings loaded in the array accept.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39210056
if echo "${accept[*]}" | /usr/xpg4/bin/grep -qFw "$ignore" ; then ...

("q" = quiet, I dont't think you need to see grep's output)
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 39210752
thanks...I'm getting a -F and -q option error.  ("although I agree with you").  I'm guessing SOLARIS does not like that.  does </dev/null work in this case?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39210771
Did you really use /usr/xpg4/bin/grep ?

Anyway, >/dev/null will work (not </dev/null ...!), so you don't need -q.

-F is only needed to keep grep from interpreting what's in "$ignore" as a regular expression.

If you don't expect any regex metacharacters in that string you can omit -F as well.
In that case you never had to use "fgrep", however. grep -w would have done the trick in Linux too.


if echo "${accept[*]}" | /usr/xpg4/bin/grep -w "$ignore" >/dev/null ; then ...
0
 
LVL 9

Author Closing Comment

by:Evan Cutler
ID: 39210792
yeah, I did, even ran it inside /usr/xpg4/bin...It' didn't like -q.
However, I am not using regex...so this is good.  thanks.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39210824
The current directory ( "." ) is most probably not contained in your PATH, and if it is, it appears most probably not before /usr/bin, the home of the standard grep.

So running a command from inside a directory generally has no effect, since the directories in PATH are the only places where executables are searched.

Thx for the points!

wmp
0
 
LVL 84

Expert Comment

by:ozo
ID: 39210826
Try this:
xx=(${accept[*]/$ignore/})
if [[ ${#xx[*]} -lt ${#accept[*]} ]]
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question