simple syntax terminal command question

zmbarker
Contributor

I am trying to clean up the results that report back on my EA. I am sure this is something simple but my eyes are getting cross-eyed trying to get the correct syntax.

I have an EA that reports back the board-id of the systems.

echo "<result>$(ioreg -p "IODeviceTree" -r -n / -d 1 | grep "board-id")</result>"
reports back "board-id" = <"Mac-6F01561E16C75D06">

To delete the "board-id" = I added the | awk '{print $3}'

echo "<result>$(ioreg -p "IODeviceTree" -r -n / -d 1 | grep "board-id" **| awk '{print $3}'**)</result>"
reports back **<"**Mac-6F01561E16C75D06**">**

To delete the "" I added the | sed s/"//g

echo "<result>$(ioreg -p "IODeviceTree" -r -n / -d 1 | grep "board-id" | awk '{print $3}' **| sed s/"//g)**</result>"
reports back **<**Mac-6F01561E16C75D06**>**

To delete the < I added the | sed s/<//g

echo "<result>$(ioreg -p "IODeviceTree" -r -n / -d 1 | grep "board-id" | awk '{print $3}' **| sed s/<//g**)</result>"
reports back **"**Mac-6F01561E16C75D06**">**

To delete the < & " I added the | sed s/<"//g

echo "<result>$(ioreg -p "IODeviceTree" -r -n / -d 1 | grep "board-id" | awk '{print $3}' **| sed s/<"//g**)</result>"
reports back Mac-6F01561E16C75D06**">**

I cannot get the syntax correct to report without <" & ">
What I want it to report back is Mac-6F01561E16C75D06

1 ACCEPTED SOLUTION

localhorst
Contributor

Have you considered replacing awk with the only true script language?

ioreg -p "IODeviceTree" -r -n / -d 1  | 
  perl -n -e '/board-id.*<"(.*)">.*/ && print "<result>$1</result>
"'

HTH?
Marko

View solution in original post

5 REPLIES 5

localhorst
Contributor

Have you considered replacing awk with the only true script language?

ioreg -p "IODeviceTree" -r -n / -d 1  | 
  perl -n -e '/board-id.*<"(.*)">.*/ && print "<result>$1</result>
"'

HTH?
Marko

zmbarker
Contributor

Thanks Marko, you are the best.

mm2270
Legendary Contributor III

Or, you could stick with awk and use awk's special multi character field separator in combination with its regex matching to print only the text between the second set of "s

echo "<result>$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'["|"]' '/board-id/{print $4}')</result>"
<result>Mac-94245B3640C91C81</result>

mm2270
Legendary Contributor III

Dreaded double post...

evarona
New Contributor II

I got it working by substituting sed with tr

$ ioreg -p "IODeviceTree" -r -n / -d 1 | grep "board-id" | awk '{print $3}'| tr -d "<>