[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Solaris KSH fgrep

Posted on 2013-05-30
12
Medium Priority
?
514 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 80

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 80

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 80

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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

649 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