Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to AWK INXI?
#1
how do you awk inxi. or is there another way to get the same result? reed on.

i am trying to get an output of something like this

Code:
Machine: TOSHIBA Satellite L16574 PSKXXX-XXXXXX



i have tried
Code:
inxi -M | awk '/^Machine:/ {print $2 " / " $3}'
but no output. and i have tried
Code:
inxi -M | awk '{print $6 " "$8}' | grep TOSHIBA

But this only works with Toshiba. Is there another way to get this info printed out like that. or am i just awking wrong?

i have never tried to awk inxi before so i don't even know if it can be done correctly.

any advise is appreciated thank you in advance.

EDIT
-------------------------------------------------------------------
I have mostly answered my own question. I played around with it until i came up with
Code:
inxi -M | awk '{print $5 " " $6 " "$8  " " $9 " " $11}' | grep System | awk '{print $2 " " $3 " "$4 " " $5 " " $6}'
this works, but is kinda silly. it awks a grep, and greps an awk. which is why i went ahead and posted anyway. I am still asking myself and everyone, is there a better way?

again, thanks.

and

kudos.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#2
I tried it on various laptops and got mixed results. The fields were different on each because of spaces in model names, etc. Here's what I got with my Panasonic Toughbook runnng Lubunt 18.04:
[code]
$ inxi -M
Machine: Device: laptop System: Panasonic product: CF-T8EWDTZAM v: 001 serial: N/A
Mobo: Panasonic model: CFT8W-1 v: 1 serial: N/A BIOS: American Megatrends v: V1.50L13 date: 01/26/2009
$ inxi -M |awk '/Machine:/ {print $6 " / " $8}'
Panasonic / CF-T8EWDTZAM
[code]

You may need to look at the output of inxi without piping it to awk and then try different combinations of the fields you want to print. Hope this helps.
Rick Romig
"It's never wrong to introduce a child to Linux."
@ludditegeek
Rick's Tech Stuff
GitHub
Reply
#3
(06-05-2020, 02:20 PM)rickromig Wrote: I tried it on various laptops and got mixed results. The fields were different on each because of spaces in model names, etc. Here's what I got with my Panasonic Toughbook runnng Lubunt 18.04:
[code]
$ inxi -M
Machine:  Device: laptop System: Panasonic product: CF-T8EWDTZAM v: 001 serial: N/A
          Mobo: Panasonic model: CFT8W-1 v: 1 serial: N/A BIOS: American Megatrends v: V1.50L13 date: 01/26/2009
$ inxi -M |awk '/Machine:/ {print $6 " / " $8}'
Panasonic / CF-T8EWDTZAM
[code]

You may need to look at the output of inxi without piping it to awk and then try different combinations of the fields you want to print. Hope this helps.

that is cleaner. When I adapt it to fit the format needed, like this

$ inxi -M | awk '/Machine:/ {print $6 " "$8 " " $9 " " $11}'

the output is (basically)
TOSHIBA Satellite L61325 PSXXXX-XXXXXX             # numbers have been changed

which is the same output as the above mile long string.
So, ya. that is better. I will check it on my other systems for consistency this evening.

thanks for the quick response

kudos
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#4
Can you? Yes, you can 'awk' basically anything. Does it make sense? Not at all; Piping a programs output, which is designed to be read by humans and not parsed, into 'sed', 'awk', 'cut' and other such programs is not sane, but rather abusing of UNIX pipes and tools.

inxi can print its output in the JSON format, which is designed to be computer-parsed.
Code:
inxi --output json --output-file print
Now you can use a command line JSON parser, like 'jq', to sanely get the data you want.
Reply
#5
I have never trusted JAVA unless it is coffee. to be honest, it has been ten years sense i have touched anything in with JSON as far as coding. unless it was to reference another file written in JSON.

as crazy and messy as it is, i would prefer tpo keep the code language all the same in the script. i could do it in python but then its another file that has to be referenced.

Or am i not understanding correctly?

could you clarify?

again thanks.

kudos
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#6
(06-05-2020, 01:02 PM)eliasw4u Wrote: how do you awk inxi. or is there another way to get the same result? reed on.

i am trying to get an output of something like this

Code:
Machine: TOSHIBA Satellite L16574 PSKXXX-XXXXXX



i have tried
Code:
inxi -M | awk '/^Machine:/ {print $2 " / " $3}'
but no output. and i have tried
Code:
inxi -M | awk '{print $6 " "$8}' | grep TOSHIBA

But this only works with Toshiba. Is there another way to get this info printed out like that. or am i just awking wrong?

i have never tried to awk inxi before so i don't even know if it can be done correctly.

any advise is appreciated thank you in advance.

To troubleshoot your awk command anomaly, let us look closer at the inxi -M output using a grep and od -c commands as follows:



$ inxi -M | grep Machine | od -c

0000000 033   [   1   ;   3   4   m   M   a   c   h   i   n   e   :    
0000020     033   [   0   ;   3   7   m     033   [   1   ;   3   4   m
...
$


Notice, the escape codes before the Machine word representing the terminal font color settings. You would think the program would detect a pipe connection on the standard output instead of a tty and default to using non-color output. It does not, fortunately you can correct it by using the -c0 option.


$ inxi -Mc0 | awk '/^Machine:/ {print $L }'

Machine:   Device: oracle System: innotek product: VirtualBox v: 1.2 serial: N/A

$


Notice this time, the output contains the line beginning with the "Machine" word. 


I believe in the K. I. S. S.  principle.  The inxi program is nothing more than a front end (wrapper) to a lot of other commands or at least to the same information as the dmidecode program in this case. Fortunately, the Linux kernel via sysfs provides direct access to this data without using the inxi or dmidecode programs. 


$ cd /sys/devices/virtual/dmi/id

$ ls
bios_date        board_vendor       chassis_version  product_uuid
bios_vendor      board_version      modalias         product_version
bios_version     chassis_asset_tag  power            subsystem
board_asset_tag  chassis_serial     product_family   sys_vendor
board_name       chassis_type       product_name     uevent
board_serial     chassis_vendor     product_serial




You can quickly display the sys_vendor and product_name using the following bash syntax:
 

$ echo "$(cat sys_vendor) / $(cat product_name)"

innotek GmbH / VirtualBox




Note, the *serial and *uuid access is set for root only. You will need to use "sudo cat" to read them.


I hope this helps you.  
Enjoy your Linux adventure.
Idea Give a person a fish, and you feed them for a day. Teach a person how to fish, and you feed them for a lifetime. ✝️ Proverbs 4:7 Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding.
Reply
#7
(06-07-2020, 02:22 AM)eliasw4u Wrote: I have never trusted JAVA unless it is coffee.

Well then you are in luck: JavaScript has nothing to do with Java and JSON has barely anything to do with JavaScript.


(06-07-2020, 02:22 AM)eliasw4u Wrote: as crazy and messy as it is, i would prefer tpo keep the code language all the same in the script.

JSON is not a "code language", as you call it. It is a way to compile data into a machine parseable format.

JSON is not that hard. There are plenty of internet tutorials on it and on parsing it with 'jq'.




But deck_luck is correct: You should probably just read the data you want manually from the sysfs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)