Fórum Ubuntu CZ/SK
Ubuntu pro osobní počítače => Software => Příkazový řádek a programování pro GNU/Linux => Téma založeno: Peterx 09 Září 2010, 14:05:48
-
Zdravim kazdeho, mam takyto problem a vobec netusim ako by som ho mohol riesit.
Pouzivam xmacro
Priklad mojho makra:
MotionNotify 465 587
MotionNotify 466 587
MotionNotify 466 587
ButtonRelease 1
MotionNotify 503 588
ButtonPress 1
MotionNotify 503 588
ButtonRelease 1
MotionNotify 509 581
ButtonPress 1
MotionNotify 509 581
ButtonRelease 1
Delay 35
MotionNotify 665 424
ButtonPress 1
MotionNotify 665 424
ButtonRelease 1
MotionNotify 649 408
ButtonPress 1
MotionNotify 649 408
ButtonRelease 1
MotionNotify 644 403
ButtonPress 1
MotionNotify 643 403
MotionNotify 642 403
MotionNotify 641 403
MotionNotify 640 403
MotionNotify 639 403
Z tohoto suboru potrebujem vytvorit dalsi subor presne takyto isty, ale k hodnotam MotionNotify potrebujem pripocitat nejake hodnoti.
Priklad:
MotionNotify 639 403 > MotionNotify 682 470
Viete mi niekto poradit?
Aby som nezabudol, ostatne riadky musia byt v povodnom stave a hodnoty MotionNotify ktore nacitavam su rozne
-
cat soubor | grep MotionNotify | cut -d ' ' -f 2
Vyhodí první číslo.
cat soubor | grep MotionNotify | cut -d ' ' -f 3
Vyhodí druhé.
Do proměnné to dáš takto:
num=$(cat soubor | grep MotionNotify | cut -d ' ' -f 3)
Práce s proměnnou je již snad jasná. Nicméně takto to nebude příliš efektivní, protože to vždy přečte celý soubor, ale pokud to není kritické tak je to asi jedno.
-
Přičte vždy stejný offset pro x a y.
x=5; y=10; awk '/^MotionNotify/ {print $1,$x+$2,$y+$3} ! /^MotionNotify/ {print $0}'
-
Tak s tymi premennymi je to nemozne lebo mam tam aj okrem MotionNotify aj nieco ine a nikdy neviem kolko krat a na akom riadku.
Na druhu moznost som spravil skript:
#!/bin/bash
x=1000
y=2000
cat m4.macro | awk '/^MotionNotify/ {print $1,$x+$2,$y+$3} ! /^MotionNotify/ {print $0}'
Ale z celeho mi funguje len cat.... ako by tam awk ani nebol, predpokladam ze tam nefunguje $x+$2, inak by to bolo fajn
Ak nahradim $x a $y cislami tak to funguje.
-
tak zu to mam:
#!/bin/bash
x=1000
y=2000
cat m4.macro | awk '/^MotionNotify/ {print $1,'$x'+$2,'$y'+$3} ! /^MotionNotify/ {print $0}'
chyba bola v tom ze premenne trebalo napisat do '' ... '$y'
Dik za rady