今年最後のポストがコレってのもどうかと思いましたが
今回はemacs lispを扱います。
短いスクリプトなら --batch --eval
$ emacs --batch --eval '(print (+ 2 (* 6 3)))' 20
計算機代わりに使えますね。
外部スクリプトを読むときには --script (emacs 23以降)
(princ "Hello, World!")
$ emacs --script hello.el Hello, World!
この程度だと旨味がないですが……
emacsの特徴であるbufferを使うと、文字列の移動、カーソル移動を使うこなしてスバラシイ結果を得る事ができます。
若葉マーク故、綺麗じゃないですが......
dquote.el
(with-temp-buffer (insert-file-contents-literally (car argv)) (search-forward "Japan") (search-forward "Japan") (search-forward "Japan") (let ((point (point))) (search-forward ".") (princ "Japan") (princ (buffer-substring point (1- (point)))) (princ ".\n")))
上記のスクリプトでjapan.txt*1の3番目のJapanが含まれる部分を引っこ抜くと……
$ cat japan.txt Japan is an island nation in East Asia. Located in the Pacific Ocean, it lies to the east of the Sea of Japan, China, North Korea, South Korea an d Russia, stretching from the Sea of Okhotsk in the north to the East China Sea and Taiwan in the south. The characters that make up Japan's name mean "sun-origin", which is why the country is sometimes referred to as the "Land of the Rising Sun". Japan is an archipelago of 6,852 islands, the four largest being Honshu, Hokkaido, Kyushu and Shikoku. Together, these four islands hold about 97 percent of the country's land area. Japan has the world's tenth-largest population, with more than 126 million people. Honshū's Greater Tokyo Area includes the de facto capital city of T okyo and several surrounding prefectures. It is the largest metropolitan area in the world, with more than 30 million residents. $ emacs --script dquote.el japan.txt Japan's name mean "sun-origin", which is why the country is sometimes referred to as the "Land of the Rising Sun".
はい、出ました。