Link to home
Start Free TrialLog in
Avatar of Lonelygirl_2012
Lonelygirl_2012

asked on

grep issue

Hi Experts,

I want the output from the below to be separate. *-power:0 and *-power:1 respectively. Could you please help.

lshw -C power| grep "^*-power:0" | grep product: | awk '{print $2}' | head -n 1
lshw -C power| grep "^*-power:1" | grep product: | awk '{print $2}' | head -n 1

Open in new window


[root@localhost local]# lshw -c power
  *-power:0 UNCLAIMED
       description: xxx
       product: xxx
       vendor: xxx
       physical id: 1
       version: 1.0
       serial: xxx
       capacity: 1600mWh
  *-power:1 UNCLAIMED
       description: To Be Filled By O.E.M.
       product: To Be Filled By O.E.M.
       vendor: To Be Filled By O.E.M.
       physical id: 2
       version: To Be Filled By O.E.M.
       serial: To Be Filled By O.E.M.
       capacity: 2000mWh
[root@localhost local]#

Open in new window

Best regards,
LG


ASKER CERTIFIED SOLUTION
Avatar of serialband
serialband
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lonelygirl_2012
Lonelygirl_2012

ASKER

Hi serialband,

lshw -C power| grep "^*-power:0" | grep product: | awk '{print $2}' | head -n 1
lshw -C power| grep "^*-power:0" | grep vendor: | awk '{print $2}' | head -n 1 
lshw -C power| grep "^*-power:0" | grep serial: | awk '{print $2}' | head -n 1 


lshw -C power| grep "^*-power:1" | grep product: | awk '{print $2}' | head -n 1
lshw -C power| grep "^*-power:1" | grep vendor: | awk '{print $2}' | head -n 1 
lshw -C power| grep "^*-power:1" | grep serial: | awk '{print $2}' | head -n 1 

Open in new window

Best regards,
LG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all,

This is exactly what I was looking for.
echo -e "Power Supply in Slot0: \n$(lshw -C power | grep "^ *\*-power:0" -A 8 | awk ' /(serial):/ {print $2}')"
echo -e "Power Supply in Slot1: \n$(lshw -C power | grep "^ *\*-power:1" -A 8 | awk ' /(serial):/ {print $2, $3, $4, $5, $6}')"

Open in new window

Instead of {print $2, $3, $4, $5, $6}. How to replace the result "To Be Filled By O.E.M." to be as "Empty" ? or if *-power:1 or 2 is detected then..

  *-power:1 UNCLAIMED
       description: To Be Filled By O.E.M.
       product: To Be Filled By O.E.M.
       vendor: To Be Filled By O.E.M.
       physical id: 2
       version: To Be Filled By O.E.M.
       serial: To Be Filled By O.E.M.

Open in new window

Best regards,
LG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi all,

Almost;
echo -e "Power Supply in Slot1: \n$(lshw -C power | grep "^ *\*-power:1" -A 8 | awk ' /(serial):/ {print $2} {if($2=="To") {$2="Empty"} print $0}')"

Open in new window

Before:
serial: To Be Filled By O.E.M.
After:
serial: Empty Be Filled By O.E.M.

Best regards,
LG
Thank you Arnold,

I'm almost there..

[root@localhost local]# echo -e "Power Supply in Slot0: \n$(lshw -C power | grep "^ *\*-power:0" -A 8 | sed -e 's/To Be Filled By O.E.M//' | awk ' /(serial):/ {print $2}')"
Power Supply in Slot0:
P1K6A............
[root@localhost local]# echo -e "Power Supply in Slot1: \n$(lshw -C power | grep "^ *\*-power:1" -A 8 | sed -e 's/To Be Filled By O.E.M//' | awk ' /(serial):/ {print $2}')"
Power Supply in Slot1:
.
[root@localhost local]#


It works now, but I'm not sure where the "." after the "Empty" comes from..
[root@localhost local]# echo -e "Power Supply in Slot1: \n$(lshw -C power | grep "^ *\*-power:1" -A 8 | sed -e 's/To Be Filled By O.E.M/Empty/' | awk ' /(serial):/ {print $2}')"
Power Supply in Slot1:
Empty.
[root@localhost local]#

Open in new window


Hi all,

It works now..

https://www.theunixschool.com/2014/08/sed-examples-remove-delete-chars-from-line-file.html

[root@localhost local]# echo -e "Power Supply in Slot1: \n$(lshw -C power | grep "^ *\*-power:1" -A 8 | sed -e 's/To Be Filled By O.E.M.*/Empty/' | awk ' /(serial):/ {print $2}')"
Power Supply in Slot1:
Empty
[root@localhost local]#

Open in new window

Best regards,
LG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you serialband, noci, arnold, MURUGESAN N for your great support,

Best regards,
LG