Section Next | Prev


5.3.3 ファイル編集3

テキストファイルを印刷しやすいように幅や段組などを行うコマンド群を解説します。
pr

【機能解説】
タイトル(ページ番号)の付加、マージン(余白)の設定、ページ設定(行あたりの文字数、ページ行数)、段組などを行う事ができます。

【入力フォーマット】
pr [ オプション ] テキストファイル...

【主なオプション】
-f
改頁コードの挿入。これがない場合はページ行数になるよう空行を挿入します。
-h header
ヘッダの文字列。特に指定しないかぎり、ファイル名が採用されます。
-t
ヘッダ、フッタを使いません。
-n
行番号を付加します。
-w width
1行あたりの行数です。デフォルトは 72
-l lines
1ページあたりの行数を指定します。デフォルトは66行
-o offset
左余白の設定。デフォルトは0文字です。
-en
タブを等価な複数の空白に置き換えます。省略時の n は 8文字です。
同様のコマンドに expand(1) があります。
-in
複数の空白を等価なタブに置き換えます。(-e の反対) 同様のコマンドに unexpand(1) があります。
-N
段組を行います。
【実行例】
  1. 簡単な使用法
    最も簡単な利用方は単純にファイル名を指定するだけです。 このとき改頁コード(-f)を指定しないと、^L のかわりに全体で 66行になるよう 空行が挿入されます
    	$ pr -f /etc/motd
    
    
    
    	04月25日 11:19 1998 /etc/motd 				ページ 1
    
    
    	Digital UNIX V4.0B  (Rev. 564); Wed Nov 12 11:44:37 JST 1997
    	Digital UNIX Japanese Support V4.0A (rev. 3.1)
    
    	^L	
    

  2. 左マージンとヘッダ定義
    左マージンは綴じ代が必要なときに有効です。またヘッダを直に指定することも できます。
    	$ pr -f -o 8 -h "pr(1) sample" /etc/motd
    
    
    	        04月25日 11:19 1998 pr(1) sample                    ページ 1
    
    
                    Digital UNIX V4.0B  (Rev. 564); Wed Nov 12 11:44:37 JST 1997
                    Digital UNIX Japanese Support V4.0A (rev. 3.1)
    
    

  3. 段組
    1行の幅が少ない場合に、1ページに数ページ分をまとめる。
    	$ cat uid.txt
    	murakami 4075
    	kawahara 4095
    	g12_siom 4031
    	kumagai  4073
    		:
    	$ pr -3 -t f uid.txt
    	murakami 4075           fukuhara 4086           yamamoto 4049
    	kawahara 4095           fukuda_s 4072           lmxadmin 200
    	g12_siom 4031           shimizu  4074           yoshida  4066
    	kumagai  4073           ikawa    4030           yoneday  4101
    	tanaka   4079           honma    4087           hayashi  4041
    	sawada   4093           araki    525            eguchia  4094
    	qman     4062           kume     4078           yamazu   518
    	yamada   502            t_yamagu 514            ftp      4998
    	sasaki   508            nishikaw 523            yositake 4026
    	okitsu   4057           hasegawa 519            watanabe 4088
    			:
    

fold

【機能解説】
テキストファイルを指定した幅に折りたたむ。

【入力フォーマット】
fold [ オプション ] ファイル...

【主なオプション】
-w width
行を width文字(Byte)で折り返します。
-s
折り返す箇所をスペースに位置づける

【実行例】
$ head find.txt
DESCRIPTION
       This manual page documents the GNU version of find.  find searches the
       directory tree rooted at each given file name by evaluating the  given
       expression  from  left  to right, according to the rules of precedence
       (see section OPERATORS), until the outcome is  known  (the  left  hand
       side  is  false  for and operations, true for or), at which point find
       moves on to the next file name.

$ fold -w60 find.txt | head -7
DESCRIPTION
       This manual page documents the GNU version of find.
find searches the
       directory tree rooted at each given file name by eval
uating the      given
       expression  from  left  to right, according to the ru
les of precedence

$ fold -s -w60 find.txt | head -7
DESCRIPTION
       This manual page documents the GNU version of find.
find searches the
       directory tree rooted at each given file name by
evaluating the  given
       expression  from  left  to right, according to the
rules of precedence

expand, unexpand

【機能解説】
expand はタブを空白に変換し、unexpand は連続した空白をタブに変換します。

【入力フォーマット】
expand [ オプション ] テキストファイル...
unexpand [ オプション ] テキストファイル...

【主なオプション】
-t tab
-t t1,t2,t3..
タブの幅を指定します。省略値は 8 です。
タブの位置をカンマで区切って、個別に指定することもできる。

【実行例】
1. expand の実行例
# タブで区切ったa,b,c,dを用意
$ cat a.txt
a       b       c       d
$ cat -t a.txt
a^Ib^Ic^Id

# タブを空白に変換し、幅を4とする
$ expand -t4 a.txt
a   b   c   d
$ expand -t4 a.txt | cat -t
a   b   c   d

# タブ位置を2,8,16とする
$ expand -t2,8,16 a.txt
a b     c       d
2. expand の実行例
$ cat -t b.txt
a       b       c       d

# 連続した空白をタブで置き換え(タブ間隔は8)
$ unexpand -t8 b.txt | cat -t
a^Ib^Ic^Id

$ unexpand -t4 b.txt | cat -t
a^I^Ib^I^Ic^I^Id

Section Next | Prev

Copyright 2007-2018 ycosSystems Misc/Body533.html