Skip to main content
Question

Scripting involving failures using grep

  • October 16, 2020
  • 1 reply
  • 0 views

Forum|alt.badge.img+5

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

Forum|alt.badge.img+16
  • Valued Contributor
  • 182 replies
  • October 16, 2020

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings