You are not logged in.
Hey, this is more of a general awk issue.
I'm running Arch on an x200 Thinkpad tablet and trying to improve on the rotate script in the wiki.
Currently, the wiki's script has predefined values for the stylus/eraser devices that don't work for all systems (mine for example). I would like to make it so that these device names are discovered by the script at runtime so that the user doesn't have to edit the script to make it work.
In order to do this, I'm using
stylus="$(xsetwacom --list | grep STYLUS | awk '{$NF="\b"; print}')"
and likewise for the eraser.
The problem is that when the script runs, it says "Cannot find device 'Serial Wacom Tablet stylus'." even though that's the exact thing I had in the script before messing with the variable assignment.
What makes these strings different? Is there some nuance of awk that I'm missing?
Offline
What happens if you run just 'xsetwacom --list'? It doesn't look like an awk issue to me.
Mind posting the rest of the script?
Offline
Check what NF actually is, and whether you mean FS instead. (EDIT: Forget get this line, I'd made a bad assumption about the script. )
Also, you don't need grep there, you can use an awk pattern to match STYLUS.
Last edited by skanky (2010-09-28 08:41:22)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
#!/bin/bash
#### rotate.sh - A script for tablet PCs to rotate the display.
## This software is licensed under the CC-GNU GPL.
## http://creativecommons.org/licenses/GPL/2.0/
## http://wiki.archlinux.org/index.php/Tablet_PC
## REQUIRES: linuxwacom (http://linuxwacom.sourceforge.net/)
#### Function(s)
function set_normal {
xsetwacom set "$stylus" Rotate 0
xsetwacom set "$eraser" Rotate 0
xrandr -o normal
}
function set_right {
xsetwacom set "$stylus" Rotate 1
xsetwacom set "$eraser" Rotate 1
xrandr -o right
}
function set_left {
xsetwacom set "$stylus" Rotate 2
xsetwacom set "$eraser" Rotate 2
xrandr -o left
}
function set_inverted {
xsetwacom set "$stylus" Rotate 3
xsetwacom set "$eraser" Rotate 3
xrandr -o inverted
}
#### Variable(s)
orientation="$(xrandr --query --verbose | grep connected | grep -v dis | awk '{print $5}')"
eraser="$(xsetwacom --list | grep ERASER | awk '{$NF="\b"; print $0}')"
stylus="$(xsetwacom --list | grep STYLUS | awk '{$NF="\b"; print $0}')"
#### Main
if [ "$orientation" = "normal" ]; then
set_right
elif [ "$orientation" = "right" ]; then
set_inverted
elif [ "$orientation" = "inverted" ]; then
set_left
elif [ "$orientation" = "left" ]; then
set_normal
fi
#### EOF
Like I said, a slight modification of the original wiki script.
xsetwacom --list returns
Serial Wacom Tablet stylus STYLUS
Serial Wacom Tablet eraser ERASER
Edit:
I whipped up a short script to illustrate my problem
#! /bin/bash
therightthing="Serial Wacom Tablet stylus"
stylus="$(xsetwacom --list | grep STYLUS | awk '{$NF="\b"; print}')"
if [ "$therightthing" = "$stylus" ]; then
echo "Equal"
else
echo "Not Equal"
echo "$stylus |"
echo "$therightthing |"
fi
The vertical line is my check for trailing whitespace. When run, it returns that they're not equal, but the strings look the exact same.
Output:
Not Equal
Serial Wacom Tablet stylus |
Serial Wacom Tablet stylus |
Last edited by Pursuit (2010-09-27 23:05:39)
Offline
You get 'Serial Wacom Tablet stylus STYLUS' and you want to drop the last word? Just that or am I missing something (sorry, I'm tired)?
stylus="$(xsetwacom --list | grep STYLUS | cut -d " " -f 1-4)"
You may want to examine the string more closely, what is the last character - is it a space or something else?
Last edited by karol (2010-09-27 23:37:26)
Offline
Yeah, I'm just looking to drop the last word, regardless of how many words there are.
Would that line work if, say, the name of the device were a word longer than mine? Or is it dependent on the device name being four words long?
I believe that before attempting to modify the string with awk, the last character is the capital 'S' in STYLUS. Once awk is used, it should be the lowercase 's' in stylus. Is the error maybe coming from the \b escape sequence used to remove the trailing space?
Last edited by Pursuit (2010-09-28 00:16:34)
Offline
Yeah, I'm just looking to drop the last word, regardless of how many words there are.
Would that line work if, say, the name of the device were a word longer than mine? Or is it dependent on the device name being four words long?
I don't have a tablet so I can't check other that simulating it with echo. This example is trivial but rigid.
This will remove the last word:
stylus="$(xsetwacom --list | grep STYLUS | awk '{NF-=1} END {print}')"
See if it works.
Offline
Excellent, that's exactly what I needed
Thanks!
Offline
Regarding '\b' - IIRC it can't be the last character:
[karol@black ~]$ echo -e "123"
123
[karol@black ~]$ echo -e "12\b3"
13
[karol@black ~]$ echo -e "123\b"
123
[karol@black ~]$ echo -e "123" | wc -c
4
[karol@black ~]$ echo -e "12\b3" | wc -c
5
[karol@black ~]$ echo -e "123\b" | wc -c
5
I saved the outputs of those 'echo' commands to a file named 'test'.
[karol@black ~]$ cat test
123
13
123
The contents as seen in 'vim':
123
12^H3
123^H
As seen in 'less':
123
13
12
I think you can reconfigure the behavior regarding non-printable characters, but it's still a bit hackish.
The lines aren't equal because they actually look like this:
Serial Wacom Tablet stylus ^H
Serial Wacom Tablet stylus
Offline
If this works you can do w/o grep and have one pipe less:
stylus="$(xsetwacom --list | awk '{/STYLUS/; NF-=1} END {print}')"
Offline
If this works you can do w/o grep and have one pipe less:
stylus="$(xsetwacom --list | awk '{/STYLUS/; NF-=1} END {print}')"
I think you also don't need the END there:
$echo "blah blah STYLUS" | awk '/STYLUS/ {NF-=1; print}'
blah blah
Works either way, though.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
karol wrote:If this works you can do w/o grep and have one pipe less:
stylus="$(xsetwacom --list | awk '{/STYLUS/; NF-=1} END {print}')"
I think you also don't need the END there:
$echo "blah blah STYLUS" | awk '/STYLUS/ {NF-=1; print}' blah blah
Works either way, though.
My gut feeling told me END is not needed, but, it was already early morning here so I had to run ;P
Offline