Need to extract certain values from kudzu-output.
Hello boys 'n girls.
I'm writing this script that will enable simplified usage of cdrdao burning application.
I want to use kudzu (with -p -c cdrom options) to identify the bus,id and lun of my drive. I know I can use even cdrdao command with scanbus-option, but that requires me to run it as root (at least in Fedora), which is not desired solution. So anyway, to make the story short (I'll not go into the details regarding the script itself), let me show you how I did it.
desc: "_NEC DVD_RW ND-3500AG"
Now, from this output I need to extract values from host, id and lun lines. I only need numbers and the output should read host,id,lun - on single line, which in this case would be 4,0,0. That, I will use as the value of the variable in my script. Anyway, I'm pretty sure there is much nicer way of extracting these values, but here's how I did it. I wrote a bunch of piped commands. It works but looks clumsy.
From the output, I grep for the host (since from this line the things are getting interesting to me) + 3 lines bellow (so I get all numbers).
Then I grep out line 'channel' since I don't need it.
Then, I remove all non-nummeric characters from the remaining lines so I only have numbers left.
Then I translate new-line characters to commas, to put the numbers together and have them on the same line seperated by commas.
Finaly I delete the last ','.
The result is the desired 4,0,0 - extracted from host:, id: and lun: fields.
Do you guys have a better suggestion to "surgically" remove the stuff above and only have these values left as output, formated as above?
Please only bash-stuff, no Perl and similar things since I have zero knowledge.
Thanks in advance!
You might be able to get what you want easier by starting with this command:
This amendment strips out one of your pipe commands:
I wonder though whether there is a nice awk string that could accomplish this too. Hmm...
|All times are GMT -5. The time now is 06:07 PM.|