Ȼ/05

Top / Ȼ / 05

ե륿ץ



filter.png

ե륿ȤϡϤƥȤùƽϤץ̤ΤȤ
unix ˤñʵǽĥե륿¿. ѥפǤĤʤ뤳Ȥǡ ʣ̤ΥƥȲùñˤİ٤ˤǤ褦ˤʤäƤ.

ԥ塼ξ¿ƥȤȤ¸Ƥ뤿, ʣ̥ƥȲùñʥޥɤȤ߹碌Ǽ¸ǤƤȤƤ



ե륿ȤʣʤȤȤƤñˡ

ñǽʥե륿

ޤñʵǽ¾Ĥεǽʤե륿(ץ)Ҳ𤷤褦.
ñʽϤΥե륿Ȥ߹碌뤳ȤΤǤϤ. ñǽʥե륿ĹֻȤޤ줿ץब¿ ʬäȴƤȤ. ºݡ cpu ؤôϾ᤯ưХ⾯ʤ. ¿ƥ󥬥Ȥ.

cat

ϥեϢ뤷ƽϤץǤ뤬ºݤϤۤܤΤޤ޽Ϥץե륿ȤƻȤ뤳Ȥ¿
Ūˤϡե̾Ϳʤե̾Ȥ "-" ȤɸϤɹǡΤޤ޽ϤΤǡե륿ȤƻȤ.

ؤǸСֹǡפǤ(פ!).

ѤȤƤϡץѤ ֽϤ˹ֹͿס ֶԤޤȤ ܤ˸ʤʸ򸫤褦ˤ ʤɤ¾ rsh (ͥåȥθΥԥ塼̿)Ȥ߹碌 ֥ͥåȥͳƥե򥳥ԡ ʤɤ.

Gnome-Preferences.png ¹(1)

ls -lg | cat -n | less

ȤȡϷ̤˹ֹñˤĤ롥

Gnome-Preferences.png ¹(2)

ls -lg | rsh host 'cat > dummy.txt'

ȤȡͥåȥΥޥ "host" "dummy.txt" Ȥե˽Ϸ̤("host" Ĥɬ)



tee

Ϸ̤ɸϡפȡ֥եפξ˥ԡ ե륿
ܤ μȤ JNorth_arrow-right-sm.png tee ʬ 򸫤褦.

Gnome-Preferences.png ¹

ls -lg | cat -n | tee dummy.txt | less

ȤȡϷ̤˹ֹĤǡե "dummy.txt" ˷̤ߤĤġƱ˲̤dzǧǤ롥

grep ²

Ϳ֥ѥפޤԤ򸡺 ե륿Ǥ롥
ե륿ȤƤϡ
grep-syntax.png
ȤȤˤʤ롥
warning.png ѥϡִɽפȤäɽ(Τdzؤ. JNorth_arrow-right-sm.png ɽ).

ե̾Ϳ뤫ɤǡ
ץ˥ե̾ͿɸϤˤΥե椫鸡.
ޤե̾Ϳʤ ե̾Ȥ "-" Ȥ ɸϤɹǡ椫鸡ƽϤΤǡե륿ȤƻȤ.
¾Υե륿ե̾ˤĤƤ褽Ʊư򤹤롥



Gnome-Preferences.png ¹
㤨Сemacs ȤäƤ֤Ǥ pid Τˤϡ

ps axu | grep emacs

Ȥܤǰ̿õȤ⤹狼롥
λθ԰٤ΤΤ̤˽ФΤȤϡ

ps axu | grep '[0-9] emacs'

ps axu | awk '{print $2,$11}' | grep emacs

ʤɤȤФ褤. [0-9] ΰ̣ JNorth_arrow-right-sm.png ɽ ǡawk ΤλȤϤȤdzؤ. JNorth_arrow-right-sm.png (ޤ) awk εǽΥۥΰʬ.

notes.png μ¹򻲹ͤˤơ äץ饰 pid Ĵ٤ƤѤ kill ư 1ԤǹԤˤϤɤ褤ͤºݤˤäƤߤ褦
Ūˤϡ

  1. emacs ü

    emacs -nw

    ȤƵư
  2. emacs c-z Ȥ(ctrl 򲡤ʤ z 򲡤) emacs ߾֤ء
  3. 顤ä 1ԤǤ emacs kill 衪 ¾ΥüǤ emacs pid Ĵ٤Τȿ§Ȥ߹ߤεǽ kill %1 ȤΤȿ§
    warning.png ؤ JNorth_arrow-right-sm.png ɤɾ פФ



NG.png : ԥ塼ǡܤõΤϡ

  1. ְ㤨
  2. ٤

ᡤ"eye ball search" ȸƤФ졤򤱤٤ ԰٤ȤƤ롥 Τˤ⡤grep ХХȤ



grep ²¾

grep ²ˤ¾⤤롥 ƤȤʬȤʤˤʤΤǡƬҶˤƤ

̾
egrepѥˡֳĥɽפȤ(Τdzؤ. JNorth_arrow-right-sm.png ɽ).
fgrepѥñʤʸפȤư. Ĥޤꡤɽ̵ץС
warning.png fgrep ɬ®ǤϤʤ(fgrep f fast ǤϤʤ fixed- ƬʸǤ)
zgrep̤եषƤ顤Ȥ򸡺.
ǽϤϴĶˤäƤ



sort

Ϳ줿Ԥ ֽ֤ˡ¤ľ ե륿
sort Ū褯Ȥե륿ʤΤǡΥץޥ˥奢Ĵ١ФƤɤ.



Gnome-Preferences.png ¹ (1)

ps axu | sort -k 11 | less

ȤȥץΥꥹȤ֥ץ̾ˡס

ps -axu | sort -r -k 11 | less

ȤХץΥꥹȤ֥ץ̾εսˡפߤ뤳ȤǤ.



Gnome-Preferences.png ¹ (2)

ls -lg | sort -nr -k 4 | less

ȤСե֥礭ʽˡ¤٤Ƹ롥 HDD ̤Ĥ꾯ʤơ̵̤ʥե뤬ʤʡ Ĵ٤Ȥʤɤͭ.



notes.png sort Υޥ˥奢ɤǡɤȤ褽İƤ



uniq

٤äԤƱʤаԤˤޤȤ ե륿Ǥ롥

ǡФ sort ե륿̤Ƥ uniq ե륿̤ȡΤνʣǤΤǡƻȤȤ¿.

ʲΥץȤȾ㤦Ȥ롥ФƤȤ褤

  • -c ƱԤޤȤǤʤֲ³פϡ
  • -d ֽʣԤΤߡ׽ϡ
  • -u ֽʣʤäԤΤߡ׽ϡ



Gnome-Preferences.png ¹ (1)
/usr/bin /usr/local/bin ˤեʣʤˤϡ

(ls /usr/bin; ls /usr/local/bin) | sort | uniq | less

ȤФ褤.
warning.png sort and uniq ΥܤϤ⤦ѥʤΤdzФƤޤ

Gnome-Preferences.png ¹ (2)
դ, ʣƤեå

(ls /usr/bin; ls /usr/local/bin) | sort | uniq -d

ȤФ褤(ΥǤϷ̤ϥɤ)

tr

Ϥ줿ƥȤʸפִ̤Ԥʤե륿.
tr-syntax.png
ȤƻȤ. ܤϡʸñ̤ǤѴ(ʸפǤϤʤ)



Gnome-Preferences.png ¹ (1)

ls -lg | tr a-z A-Z

ǡls -lg η̤a A, b B, c C z Z ѴƽϤ. Ĥޤꡤʸִ.



Gnome-Preferences.png ¹ (2)
Ĺƥȥե "dummy.txt" Фơ

cat dummy.txt | tr -cd '[:print:]'

ȤȡǤʤʸƾõƽϤ롥 ξ㤨СֲԡפʤɤϤ
warning.png ץ -cd ʸ饹 [:print:] ˤĤƤϥޥ˥奢򸫤Ƥ



Gnome-Preferences.png ¹ (3)

cat dummy.txt | tr -s '\n'

ȤȡβԤη֤ĤˤޤȤ. ĤޤꡤԤõ롥



Gnome-Preferences.png ¹ (4) OK.png

cat dummy.txt | tr '[:space:]' '\n' | tr -s '\n' | sort | uniq -c | sort -nr | less

ȤȡΡñפиȶˡи¿ɽ롥
notes.png Zipf ˡ§ ˤĤĴ٤Ƥߤ补 ;͵ʤСŬʱʸѰդƤˡ§ΩĤɤǧ补



head, tail

Ϥǽ/Ǹ Ԥ.
ưŪ˵ϿɲäƤ褦ʥեѲåˤϡtail 빽Ωġ



fold

Ϥ줿Ԥ줿ޤ֤ƹʬ䤷ƽϤ. ǥեȤ 80.



Gnome-Preferences.png ¹
㤨 "dummy.txt" ȤեȤ᡼ȹͤȤ. Υ᡼뤬 1Ԥ 25ʸɽäǤɤ뤫Ӥäݤߥ졼ȤƤߤˤϡ

cat dummy.txt | fold -w 25 | less

ȤƤߤФ褤.



expand, unexpand

֤򥹥ڡѴ(expand).
ڡ򥿥֤Ѵ(unexpand).



pr

Ϥץ󥿤˽ϤΤ˥襵ʷѴ.



Gnome-Preferences.png ¹

ps axu | pr | less

ȤƤߤỌ̇̄ʬ.



wc

ϥǡ礭סñסֹԿפ.
¾Υե륿ȤȤ߹碌ƻȤȰճ˻Ȥ꤬ɤ



Gnome-Preferences.png ¹

ps axu | wc

ȤȡԿñХȿ Ϥ롥



nkf

ܸϤɤѴե륿.
ɤˤĤƤδñʲ ɤˤĤ 򻲾Ȥ. äѤʻȤ
nkf -e Ϥ euc Ѵƽ.
nkf -j Ϥ jis Ѵƽ.
nkf -s Ϥ shift-jis Ѵƽ.
nkf -w Ϥ UTF8 Ѵƽ.



Gnome-Preferences.png ¹
ƥ 'dummy.txt' ʸɤʤ

nkf -e < dummy.txt | less

Ȥɤ᤿ꤹ.



warning.png
ƥȥեΰϡɤǤʤԥɤ OS ˤäưۤʤ롥
ΤᡤOS ۤƥƥȥեꤹݤˤϲԥɤѴɬפ.
nkf ˤϲԥɤѴ뵡ǽĤƤ. ܤϥޥ˥奢ɤळ.



gzip, gunzip, zcat

ǡ ̡ࡦ

  • gzip : ϥǡ. //Lempel-Ziv 77 ˡѤ. compress Ψ褤.
  • gunzip : ̺Ѥߥǡ (᤹).
  • zcat : ̺ѤߥǡȤ .



warning.png gzip ˤäư̤줿եˤ .gz .z ȤĥҤղäΤǤ.



Gnome-Preferences.png ¹

ps axu | gzip > dummy.txt.gz

Ȥȡps axu η̤̤ dummy.txt.gz Ȥ̾Υեˤʤ.
ե륵ɤ줯餤ʤäƤ뤫(̤Ƥ뤫), ̤ʤӤ ºݤ˸Ƥߤ褦



tar

ʣΥեޤȤưĤΥǡ ƽϤ롥 ǸʣΥե᤻롥
warning.png ̾λȤϥޥ˥奢򸫤褦



tar ե륿ȤƻȤ򤤱ѤȤơ ʣΥեǥ쥯ȥι¤ȡְưפ㤬롥

Gnome-Preferences.png ¹

tar cf - -C ǥ쥯ȥA . | tar xpf - -C ǥ쥯ȥB

Ȥȡǥ쥯ȥA Ȥ򤽤Τޤޥǥ쥯ȥ B إԡǤ. ѥפδ֤ rsh ʤ 򶴤Хͥåȥۤƥǥ쥯ȥι¤򥳥ԡǤ.



(ޤ) awk εǽΥۥΰʬ

ǤϤȤꤢϹԤ ܤ򹥤ʤ褦¤ľ ե륿Ȥ򤷤Ƥ
Ĥޤꡤ ڡ ,() Ƕڤ줿ǡϢʤϤФơ ڤ줿ǡȴФ롥
ǡϡ $1, $2, ... Ȥ̾ǰ.

Gnome-Preferences.png ¹

ps axu | awk '{print $2, $11}'

ʤɤȤäƤߤа֤ǤϤ.



warning.png awk ϥץǽʹⵡǽե륿Ǥ롥Ȥdzؤ֡



cut

ڤ줿ǡϢʤϤФơڤ줿ǡȴФ ե륿.
awk ȻƤ뤬awk ͻ̤ʤ



Gnome-Preferences.png ¹

ps axu | cut -f 2,11 -d " "

Ȥȡֶڤʸ = ڡפȤ 2ܤ11ܤιܤϤƤΤ awk Ӥȡͻ̤ʤפȤ̣狼



notes.png ½

˼ºݤ˹ԤƤΤ褯򤻤.



ɽ

ɽȤϡʸνɽ˹ͤ줿롼ΰĤǤ.
ʹ֤ʸԤʤȤꤷʸʹ֤Τϴñ ФΤ˻ꤹΤ񤷤ȤȤɤ뤳Ȥ.



warning.png 㤨Сre ǻϤޤäơtion ǽñʸ椫õƤ, Ȥؼ򥳥ԥ塼ˤɤ

ʹ֤˾Τĸ̩ɽˡȤơɽ롥



warning.png ɽΤΤΥޥ˥奢ϡ

  • Linux ξ man 7 regex
  • FreeBSD ξ man re_format

Ȥɤ롥



ɽμȤΰ̣

ḥ̂
̾ʸ᥿饯Ǥʤʸ. ʸȤɽ. ᥿饯Ȥϡ
ɽǤ \ ^ $ . [ ] * 7ʸ
ĥɽǤ \ ^ $ . [ ] * + ? { } ( ) ¦ 14ʸ򤤤.
\m᥿饯 m ΰ̣Ǿä̾ʸȤư(פȤ).
^Ƭɽ.
$ɽ.
. (ԥꥪ)Ǥդΰʸɽ.
[ ][ ] ǰϤޤ줿ʸΤɤ줫ʸɽ.
[ ] Ǥ̤ "-" Τߤ᥿饯Ȥʤꡤ ¾Υ᥿饯̾ʸȤư.
"-" ̾省饯Ȥưˤϡ "---" (ϥե򻰤ķҤ) Ƚ񤱤Ф褤.
[ c1 - c2 ]ʸ c1 c2 ޤǤϰϤʸΤɤ줫ʸɽ.
[^ ][^ ] ǰϤޤ줿ʸˡִޤޤʤװʸɽ.
*ľɽ 0 ʾη֤ɽ.
+ľɽ 1 ʾη֤ɽ.
?ľɽ 0 1󸽤뤳Ȥɽ.
\{ m \}{ m }ľɽ m η֤ɽ.
\{ m, \}{ m, }ľɽ m ʾη֤ɽ.
\{m, n\}{m, n}ľɽ m ʾ n ʲη֤ɽ.
\( \)( )Ϥޤ줿ʬ򥰥롼ײ.
\NN ܤΥ롼ײ줿ɽפ(N= 1,2,..9).
¦ľľɽΡ֤ɤ餫פɽ



ʤGNU եȥˤϰʲΤ褦ʳĥɲäƤ롥

GNUḥ̂
\<ñƬɽ.
\>ñɽ.
\bñƬɽ.
\Bñ(Ƭ)ʳɽ.



Gnome-Preferences.png (1)
㤨С

re.*tion

ϡre ǻϤޤäơtion ǽñפ˶ᤤɽ
ΤΤǤʤΤϤʤ 褯ͤƤߤ褦



Gnome-Preferences.png (2) emacs ɽѤƤߤ

㤨С web page ե d.html Ȥ¸.
ơΥե뤫顤html Υ (< ... > Ȥ) Ȥͤ롥
κȤϡ㤨 emacs ǤˤϼΤ褦ˤФ褤.

  1. emacs ǥեɤ߹.

  2. '' M-x replace-regexp '' Ȥ.

  3. ߥ˥Хåե '' Replace regexp: '' ȽФơϤ׵ᤵ.
    ִ٤оݡפɽϤ ȤȤǤ.

    ǡ '' <[^>]*> '' Ϥ Return 򲡤.

  4. ߥ˥Хåե '' Replace regexp <[^>]*> with: '' ȽФơϤ׵ᤵ.
    ֲִΤפɽϤ ȤȤǤ.

    ǡñ˾õΤǡ ֶפϤ(Ĥޤꡤ񤫤 Return 򲡤).

  5. ?

notes.png ½

  1. κȤºݤ˹Ԥ Ѥɽ򤷤ʤ顥



ץޥ֥ ե륿

ñǽե륿ǤϾ٤Ťʣʥե륿Ԥʤˤϡ ΤޤޤǤϡ 륹ץȤ뤫 ̾ǥץȤʤɤι԰٤ɬפȤʤ.
륹ץȤ¤ƽʽ񤷤 ̾ǥե륿ƤץहΤ̵̤¿.
ǡե륿ץ༫Ȥʣʥե륿ץǤС ե륿ʵǽĤġ̵̵ʣʽˤǤȤΤ. 줬֥ץߥ󥰲ǽʡץե륿¸߰յǤ.

ץߥ󥰲ǽʥե륿ץȤƤϡ sed, awk, perl, ruby ͭ̾Ǥ. ֵܹǤϡ sed ˤĤƤޤñ˲⤹.

sed

sed ϡ 1 Ԥ ® ɽλȤʸִġ ȤäƤ褤.

sed λȤ(ʸˡ)

ե륿ȤƤ
sed-syntax.png
Ȥ褦Ѥ. Ǥ֥ץȡפȤϡsed ưꤹ뤿(桹줫)ץΤȤǤ.
ץ -n ˤĤƤϤȤdzؤ֡



sed ưץȤδ

sed ϤԤĽƤ. Ĥޤꡤñ̤ϡֹԡפǤ. ơ sed ΥץȤϴŪˡ

 оݤȤʤԤλ {
 ޥ
 ޥ
 ޥ
 ޥ
 }

Ȥ¤򤷤Ƥ.
ޥɤĤʤ { } פ.
оݹԤλ꤬פǤ(ĤޤꡤƤϹԤоݤȤ)ϡ

 ޥ
 ޥ
 ޥ
 ޥ

ȥޥɤϢͤƤ褤.

ơsed ư

  • оݤȤʤԤˤϡ ƤΥޥɤŬѤƤ顤
  • оݳιԤˤϡĤʤˤ⤷ʤǤΤޤޤˤơ

ɤˤϤ ȤΤưǤ.

warning.png ư ץ -n ѤϡֽϤ̿ᤵ줿Ȥʳϡ׽Ϥʤʤ롥

ޤȤꤢ
ֽ줿ԤΤ߸ϡ-n ץȡp ե饰 p ޥɤȤ
ȳФƤפ.



sed ץȤǤνоݹԤλˡ

оݤȤʤԤꤹˡ,

  • ֹ 10 Ƚ񤤤 10ܤΤ.
  • /ɽ/ ɽִޤ׹(ʣꤦ).
  • $ ǽ.

3̤.
10, /win/ Τ褦Ĥλ ,() ǷҤƽ񤤤ˤϡ 10ܤ win ޤԤޤ Ȥϰϻˤʤ.

sed ץȤǤΥޥ

sed Υץȥޥɤϰʲ̤ꡥ

ޥ̣
s/ִѥ/ִѥ/ե饰ѥ(ɽ) ˹פʸ򿷥ѥ֤.
ִѥˤϡ̤ & Ȥ᥿饯Ȥ. ִѥ˹פʸ󤽤ΤΡɽ.

ե饰ϰʲ̤ꡥ
g γʸơִ.
N γʸΡN ܡפִ.
p ִԤʤ줿ʤСɽ.
pιԤɬɽ.
dιԤ.
qsed ΤΤλ.



Gnome-Preferences.png ¹ (1)

ps axu | sed -e 's/daemon/WhoAreYou?/g' | less

Ȥȡ äƤ뤫



Gnome-Preferences.png ¹ (2)

ˡ

ps axu | sed -n -e 's/daemon/WhoAreYou?/gp' | less

Ȥȡʬ䤹



Gnome-Preferences.png ¹ (3)
󤢤ե̾򡤰Ƥ˵Ūѹ 㤨С*.text Ȥե򤹤٤ *.txt Ȥե̾ѹȤ롥

\ls *.text | sed -n -e 's/\(.*\).text$/mv & \1.txt/gp'

Ȥȡ֤ѹΤβפǤ롥
Ūˤϡ㤨 a.text, b.text, c.text, ... Ȥե뤬 ֤ǤΥޥɤǤĤȡ

 mv a.text a.txt
 mv b.text b.txt
 mv c.text c.txt

Ȥ̤.

warning.png ǽ ls Ƭ \ դƤͳϡ alias ̵뤷ơǤΡls ư뤫Ǥ롥 ˤꡤ(ʬꤷ) alias ˤäϤԤȰ㤦Ȥ򤱤뤳ȤǤ롥

ơȤϤΡַ̡פ򥷥륹ץȤˤƤ褤뤽ΤΤϤƤɤ.
㤨С

\ls *.text | sed -n -e 's/\(.*\).text$/mv & \1.txt/gp' | sh

ʤɤȤȡƤ˥ե̾˾̤ѹǤ롥



notes.png ½: ½Ѥ˥ǥ쥯ȥѰդ˼½Ѥ եĤäơƤߤ褦



ݡ

ʲβˤĤǽ¤긭ĴȹͻԤ
AppliedMath7-Report-05
Ȥ̾Ĥ e-mail ˤƶ˥ݡȤȤФ. ʤݡȤ e-mail TeX Ǻ̤ˤФƤ褤.

  1. Tsushima Tsusima Tushima Tusima ȤʸޤԤǡ椫õˤϤɤ褤Ҥ٤.

  2. եȤιƬƤ " > " Ȥʸդä. ɤФ褤.

  3. եǡǯ '' 2011.05.19 '' Ȥ褦ʷǵҤƤ.
    '' 19/May/2011 '' Ȥ˽ɤФ褤( 1 Jan. ˡ2 Feb. ˡĤľΤǤ).

  4. (;͵ΤԸ) ̤ʸϤ򡤡ִפѴˡͤ补



about Icons, ClipArts

For details, see JNorth_arrow-right-sm.png this.