cut 명령어
상위 문서: {{ item.title }} -
bash command
cut out selected portions of each line of a file
Examples
첫 3 글자를 출력한다
$ echo 'hello world' | cut -c 1-3
$ echo 'hello world' | cut -c1-3 # 이렇게 붙여도 된다
3 번째 글자부터 마지막 글자까지 출력한다
$ echo 'hello world' | cut -c 3- # 결과는 llo world
공백을 기준으로 2 번째 필드(f) 를 출력한다
$ echo 'hello world' | cut -d' ' -f2
필드 범위 출력
$ cut -d: -f -4 /etc/passwd # :를 기준으로 1 ~ 4 번 필드를 출력
$ cut -d: -f 4- /etc/passwd # :를 기준으로 4 ~ 마지막 필드를 출력
$ cut -d: -f 2-4 /etc/passwd # :를 기준으로 2 ~ 4 번 필드를 출력
$ cut -d: -f 3,5,8 /etc/passwd # :를 기준으로 3, 5, 8 번 필드를 출력