[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Solaris KSH fgrep

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

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 81

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 81

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 85

Expert Comment

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

Featured Post

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.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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.
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.
Suggested Courses
Course of the Month19 days, 12 hours left to enroll

872 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