[kwlug-disc] Parsing Devices Names

Khalid Baheyeldin kb at 2bits.com
Sat Dec 3 10:14:48 EST 2016


Many ways to do this.

Here is a quick one:

wodim --devices |
  grep '/dev=/' |
  awk '{print $2}' |
  sed -e 's/\'\/dev=\'//'

Also

  tr -d "'"

Will strip the single quotes, making the sed line more readable.

On Sat, Dec 3, 2016 at 9:32 AM, John Driezen <jdriezen at sympatico.ca> wrote:
> I am doing some modifications to the scripts supplied with vortexbox 2.4.  I
> am trying to parse the output of wodim --devices to extract the device
> names.
>
> wodim: Overview of accessible drives (4 found) :
> -------------------------------------------------------------------------
>  0  dev='/dev/sr0'    rwrw-- : 'HL-DT-ST' 'DVD-RAM GH22NS30'
>  1  dev='/dev/sr1'    rwrw-- : 'HL-DT-ST' 'DVDRAM GH22NS50'
>  2  dev='/dev/sr2'    rwrw-- : 'HL-DT-ST' 'DVDRAM GH22NS50'
>  3  dev='/dev/sr3'    rwrw-- : 'ATAPI' 'DVD A  DH16A6L'
> -------------------------------------------------------------------------
>
> The following command
>
> wodim --devices | awk '/dev=/ { print substr($2,index($2,"/"),8) }'
>
> produces the following desired output:
>
> /dev/sr0
> /dev/sr1
> /dev/sr2
> /dev/sr3
>
> except that I don't want to assume that the length of the device name is
> only 8 characters long.  Suggestions anyone?  A sed script would be
> acceptable as well, but I don't know sed.
>
> John Driezen
>
> jdriezen at sympatico.ca
>
>
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>



-- 
Khalid M. Baheyeldin
2bits.com, Inc.
Fast Reliable Drupal
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci
For every complex problem, there is an answer that is clear, simple,
and wrong." -- H.L. Mencken





More information about the kwlug-disc mailing list