I have an "lsusb" output as below:
khalemi@hpx:/opt$ lsusb -d 0c2e:0200
Bus 002 Device 004: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
Bus 002 Device 006: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
Q) How can I use "sed" to reformat the output ( using delimiter ---) to be like
Bus 002 Device 004: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
---
Bus 002 Device 006: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
I will then pass this output to another process like php script, and explode/split it using (---) delimiter into array.
please help.
In php, you could do like
Through preg_split
$str = <<<EOT
Bus 002 Device 004: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
Bus 002 Device 006: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
EOT;
$split = preg_split('~\n~', $str);
print_r($split);
With explode
,
$split = explode("\n", $str);
This splits the input according to the newline character.
Output:
Array
(
[0] => Bus 002 Device 004: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
[1] => Bus 002 Device 006: ID 0c2e:0200 Metrologic Instruments Metrologic Scanner
)