CUTコマンドで特定の文字を取り出す
ファイルやコンソール出力の表示を操作したい時に便利なコマンドです。
【ファイル表示操作例】
[root@localhost ~]# cat T1
1,TEST1,LAST1
2,TEST2,LAST2
3,TEST3,LAST3
4,TEST4,LAST4
5,TEST5,LAST5
[root@localhost ~]# cut -d, -f1,2 T1
1,TEST1
2,TEST2
3,TEST3
4,TEST4
5,TEST5
[root@localhost ~]# cut -c 9 T1
L
L
L
L
L
[root@localhost ~]# cut -c 9- T1
LAST1
LAST2
LAST3
LAST4
LAST5
【権限などコンソールの表示操作例】
[root@localhost ~]# ls -l | cut -c 1-10
合計 88
drwxr-xr-x
drwxr-xr-x
-rw-r--r--
drwxr-xr-x
drwxrwxr-x
drwxr-xr-x
drwx--x--x
drwxr-xr-x
drwxrwxr-x
drwxr-xr-x
drwxr-xr-x
[root@localhost ~]# Right=`ls -l $1`
[root@localhost ~]# pram=`echo $Right | cut -c 2-10`
[root@localhost ~]# echo $pram
計 88 drwx
[root@localhost ~]#
[root@localhost ~]# cut --help
使用法: cut [オプション]... [ファイル]...
ファイルの各行から選択した部分だけを切り出して, 標準出力に表示します.
長いオプションに必須の引数は短いオプションにも必須です.
-b, --bytes=LIST select only these bytes
-c, --characters=LIST select only these characters
-d, --delimiter=DELIM use DELIM instead of TAB for field delimiter
-f, --fields=LIST select only these fields; also print any line
that contains no delimiter character, unless
the -s option is specified
-n with -b: don't split multibyte characters
--complement complement the set of selected bytes, characters
or fields.
-s, --only-delimited 区切り文字を含まない行を出力させない
--output-delimiter=STRING 出力の区切り文字として STRING を使用
デフォルトでは入力の区切り文字を使用
--help この使い方を表示して終了
--version バージョン情報を表示して終了
Use one, and only one of -b, -c or -f. Each LIST is made up of one
range, or many ranges separated by commas. Selected input is written
in the same order that it is read, and is written exactly once.
Each range is one of:
N N'th byte, character or field, counted from 1
N- from N'th byte, character or field, to end of line
N-M from N'th to M'th (included) byte, character or field
-M from first to M'th (included) byte, character or field
With no FILE, or when FILE is -, read standard input.
[root@localhost ~]#
カテゴリ
Linuxトラックバック(0)
このブログ記事を参照しているブログ一覧: CUTコマンドで特定の文字を取り出す
このブログ記事に対するトラックバックURL: http://variable.jp/mt/mt-tb.cgi/30

コメントする