shuf
텍스트 처리
쓰는 꼴
shuf [file]줄을 무작위 순서로 내놓습니다. GNU coreutils라 macOS에는 없고, 대신 쓰는 sort -R은 같은 줄을 한데 묶어 버립니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| -n | Print only N lines |
| -e | Treat the arguments themselves as the lines |
| -i | Draw from a number range, as in -i 1-100 |
| -r | Allow the same line to come out more than once |
| -o | Write to a file instead of standard output |
| --random-source | Use a fixed source so the shuffle can be repeated |
예시
shuf -n 1 names.txtPicks one line at random.
shuf -i 1-49 -n 6Six different numbers between 1 and 49.
sort -R names.txtThe nearest thing on a machine without shuf.
파이프로 이어 쓰는 것이 본래 용도입니다. 한 명령이 다 하는 것보다 셋을 잇는 편이 짧습니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. shuf은 무엇을 하나요?
줄을 무작위 순서로 내놓습니다. GNU coreutils라 macOS에는 없고, 대신 쓰는 sort -R은 같은 줄을 한데 묶어 버립니다.
Q. 어떻게 치나요?
shuf [file] — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 6개입니다. 전체 목록은 man shuf에 있습니다. 이 명령은 텍스트 처리 갈래입니다.
같이 보는 명령
man 페이지: man shuf