?
Solved

Solaris KSH fgrep

Posted on 2013-05-30
12
Medium Priority
?
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 79

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 79

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 79

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

765 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