Dear Folks,

I want to comment out certain lines in a file that match a particular pattern. The file contains lines with characters like: {, }, ==, and ". Specifically, I want to replace lines beginning with

ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0109",

with

# ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0109",

I have been unsuccessful in including the pattern as above and have had to work around using just the two number patterns like so:

--------
#!/usr/bin/perl -i.bak -pl
use warnings;
use strict;
m/07b4/ and m/0109/ and s/$_/# $_/;
--------

This works, but leaves me wondering how I could include the full pattern, including metacharacters. Using \Q did not help, but perhaps I was doing something wrong.

I have included some sample lines that can be used as an input file.

--------
ATTRS{idVendor}=="0553", ATTRS{idProduct}=="0202", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="06bd", ATTRS{idProduct}=="0403", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0109", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="06bd", ATTRS{idProduct}=="0404", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="04fc", ATTRS{idProduct}=="504b", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0100", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0105", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0114", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0114", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0109", MODE="0660", GROUP="plugdev"
ATTRS{idVendor}=="07b4", ATTRS{idProduct}=="0105", MODE="0660", GROUP="plugdev"
--------

Thanks.

Chandra

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to