Scripting involving failures using grep

michaelmcgaw
New Contributor III

I am using dscl to pull membership information from an AD group. I break the response down to a series of lines containing computer names or user names; this is the result of passing the dscl output through a pipeline. I have verified that the pipeline is extracting the information I need. It's just this final step...

At the end of the pipeline I want to use some method to return lines containing the values in either of two variables: $myHostName or $myUserName (which are determined elsewhere in the script).

I've tried things like:

grep -e $myHostName -e $myUserName grep -E -o "$myHostname|$myUserName"

Plus a bunch of other things the list of which is getting frustratingly long.

I'm not insisting on grep, I just need to be able to pull lines that contain $myHostName or $myUserName; that seemed to me to be a reasonable approach.

However, I am not having any luck.

Can anyone provide suggestions for me to try?

Thank you in advance!

1 REPLY 1

AdamCraig
Contributor III

If I think I get what you want I'd do something like this

#!/bin/sh

containsHostName=$( echo "${fullList}" | grep "$myHostName")
containsUserName=$( echo "${fullList}" | grep "$myUserName")

containsEither="$containsHostName $containsUserName"

Probably not the best solution. But I think it'll get you what you want.