You are not logged in.
Pages: 1
Any simpler and better way to do this task to extract a selected device configures in xorg.conf between Section and EndSection. In this sample the mouse. This what I did. It works but will not be accurate with all styles of xorg.conf(s)
mouse="mouse"
# Count how many lines between 'Section "InputDevice"' and 'EndSection'
SEARCH=`grep Driver $ConfigFILE | grep $mouse`
grep -A 50 -B 5 "$SEARCH" $ConfigFILE | grep -A 50 -B 5 "$SEARCH" | grep -A 50 InputDevice >/tmp/search.hwd
n=""
cat /tmp/search.hwd | while read LINE; do
if [ "$LINE" = "EndSection" ]; then
exit 1
else
n=$((n+1))
echo "$n" >/tmp/num.hwd
fi
done
#Extract
n=`cat /tmp/num.hwd`
SEARCH=`grep Driver $ConfigFILE | grep $mouse`
MTEXT=`grep -A $n -B 5 "$SEARCH" $ConfigFILE | grep -A 50 InputDevice | grep -B 50 EndSection`
echo "$MTEXT" >/tmp/hwd.tmp
The result (/tmp/hwd.tmp) would be something like this:
Section "InputDevice"
Identifier "Serial Mouse"
Driver "mouse"
Option "Protocol" "Microsoft"
Option "Device" "/dev/ttyS0"
Option "Emulate3Buttons" "true"
Option "Emulate3Timeout" "70"
Option "SendCoreEvents" "true"
EndSection
Section "InputDevice"
Identifier "PS/2 Mouse"
Driver "mouse"
Option "Protocol" "auto"
Option "ZAxisMapping" "4 5"
Option "Device" "/dev/psaux"
Option "Emulate3Buttons" "true"
Option "Emulate3Timeout" "70"
Option "SendCoreEvents" "true"
EndSection
Section "InputDevice"
Identifier "USB Mouse"
Driver "mouse"
Option "Device" "/dev/input/mice"
Option "SendCoreEvents" "true"
Option "Protocol" "IMPS/2"
Option "ZAxisMapping" "4 5"
Option "Buttons" "5"
EndSection
One of the shortcomes in this solution, if example "PS/2 Mouse" has more lines between the Sections than the Serial Mouse" cases a problem.
Markku
Offline
This seems to go beyond what grep was meant to do, but I was able to come up with a working solution in two passes of awk. I'm not an awk expert, so it isn't very pretty, but it seems to work well enough.
awk '/Section/, /EndSection/ {sub(/EndSection/, "EndSection\n:"); print}' /etc/X11/xorg.conf | awk 'BEGIN {RS="\n:\n"} /mouse/' > /tmp/hwd.tmp
Offline
awk '{RS=""} {ORS="\n\n"} /Driver *"mouse"/' /etc/X11/xorg.conf >/tmp/hwd.tmp
...should be enough
Last edited by ibendiben (2007-12-25 02:00:08)
Offline
awk '{RS=""} {ORS="\n\n"} /Driver[[:blank:]]*"mouse"/' /etc/X11/xorg.conf >/tmp/hwd.tmp
Yeah, that's much better. I thought there would be a simpler way! I missed the null RS case in the awk manpage. I made one minor edit to allow for the use of tabs, but otherwise it looks fine.
Offline
Thanks for the solutions. Simplified and more accurate indeed.
To extract whole default config from xorg log, in awk how to. The first line begins with Section and last line EndSection.
grep -w -A 0 -B 15 EndSection /var/log/Xorg.0.log | grep -w -A 30 Section > xorg.conf
Markku
Offline
rasat, I like your unix-lore puzzles! I was too slow on this one. Maybe for your troubles you should find the code in x.org which parses xorg.conf, and build from there! It would be easier on the brain than trying to grep/sed/awk your way out of things. But then again, grep, sed and awk one-liners are so much fun!
Offline
Pages: 1