Shell Script format question - output command results in quotes
Hey guys, first post here!
I am working on a script and my web guy wants it to output with a very specific format. I'm very close and have my echos printing most of my stuff, but I am needing quotes around the output value from a command. I'm try to get quotes around the temp (040 here) Code:
"drive_a": 040 Code:
echo -n "\"drive_a\": " Thanks guys! |
You can try command substitution in a echo statement:
Code:
echo -n "\"drive_a\": " |
You can use the octal code for `"' in the printf statement. Using grep is silly:
Code:
sudo /usr/sbin/smartctl --all -d ata /dev/sda | awk '/Temperature/{ printf "\042Drive:\042 \042%d\042\n",$4/10}' Code:
194 Temperature_Celsius 0x0022 100 100 ... |
You could also use sed to insert the quotes,
sed 's/.*/"&"/' .* says to match anything and & is what every it matched. This is not as efficient as the awk statement above, but it is easier to read. Quote:
|
Thank you very much fellas!
Lots of great tips in there for a newb scripter! Thanks again! |
Quote:
Code:
/usr/sbin/smartctl --all -d ata /dev/sda | awk '/Temperature/{ printf "\042drive_a:\042 \042%d\042\n",$4/10}' Code:
"drive_a:" "4" I'm guessing that means '40' but I would like "40" printed. EDIT: /usr/sbin/smartctl --all -d ata /dev/sda | awk '/Temperature/{ printf "\042drive_a:\042 \042%d\042\n",$4/1}' << worked for me |
All times are GMT -5. The time now is 10:01 AM. |