Skip to main content
Solved

simple syntax terminal command question


Forum|alt.badge.img+7

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

Best answer by localhorst

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 original
Did this topic help you find an answer to your question?

Forum|alt.badge.img+10
  • Contributor
  • January 29, 2014

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


Forum|alt.badge.img+7
  • Contributor
  • January 29, 2014

Thanks Marko, you are the best.


Forum|alt.badge.img+16
  • Legendary Contributor
  • January 29, 2014

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>

Forum|alt.badge.img+16
  • Legendary Contributor
  • January 29, 2014

Dreaded double post...


Forum|alt.badge.img+5
  • Contributor
  • January 29, 2014

I got it working by substituting sed with tr

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

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