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
[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]#
Best regards,
LG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all,
This is exactly what I was looking for.
LG
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}')"
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.
Best regards,LG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi all,
Almost;
serial: To Be Filled By O.E.M.
After:
serial: Empty Be Filled By O.E.M.
Best regards,
LG
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}')"
Before:serial: To Be Filled By O.E.M.
After:
serial: Empty Be Filled By O.E.M.
Best regards,
LG
ASKER
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]#
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]#
ASKER
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]#
ASKER
Hi all,
It works now..
https://www.theunixschool.com/2014/08/sed-examples-remove-delete-chars-from-line-file.html
LG
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]#
Best regards,LG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you serialband, noci, arnold, MURUGESAN N for your great support,
Best regards,
LG
Best regards,
LG
ASKER
Open in new window
Best regards,LG