LoginSignup
1
4

More than 5 years have passed since last update.

Linux基本コマンド cut

Posted at

オプション

オプション 説明
-b リスト 切り出す位置のリストをバイト数で指定
-c リスト 切り出す位置のリストを文字数で指定
-f リスト 切り出す位置のリストを区切りのフィールドで指定
-d リスト 区切り文字を指定、デフォルトはタブ

リスト指定

オプション 説明
N N番目
N-M N ~ M
N- N ~ 最後
-M 最初 ~ M

利用例

バイト数を指定して切り出す

$ ls -l * | cut -b 1-10,42-
-rw-rw-r-- test
-rw-rw-r-- uniq.txt

フィールドを指定して切り出す

# ユーザー一覧
$ cat /etc/passwd | cut -f1 -d':'
root
bin

# home directoryも出力
$ cat /etc/passwd | cut -f1,6 -d':'
root:/root
bin:/bin

# shellも出力
$ cat /etc/passwd | cut -f1,6-7 -d':'
root:/root:/bin/bash
bin:/bin:/sbin/nologin

# CSVの9列目出力
$ cut -d ',' -f 9 sample.csv

出力区切りを指定

$ cat /etc/passwd | cut -f1,6-7 -d':' --output-delimiter='----'
root----/root----/bin/bash
bin----/bin----/sbin/nologin
1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4