uniq 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-uniq
핵심 정리
- 파일에서 이웃한 중복 줄을 지웁니다. 같은 줄이 붙어 있어야 하므로 보통
sort뒤에 씁니다. - 표준 입력이나 InFile을 읽어 표준 출력이나 OutFile에 씁니다. InFile과 OutFile은 달라야 합니다.
-c(나온 횟수 표시),-d(중복된 줄만),-u(중복되지 않은 줄만).-f Fields·-Fields는 앞 필드를,-s Characters·+Characters는 앞 문자를 비교에서 뺍니다.- 입력은 텍스트 파일이어야 하고, 한 줄이 2,048바이트를 넘거나 NULL 문자를 담으면 안 됩니다.
- AIX 5.3과 6.1 문서의 내용이 같습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전 내용 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 5, 6.1 Volume 5 |
| 파일 | /usr/bin/uniq |
| 관련 명령어 | sort, comm |
목적
파일에서 반복되는 줄을 지웁니다.
영어 원문
Reports or deletes repeated lines in a file.
구문
uniq [ -c | -d | -u ] [ -f Fields ] [ -s Characters ] [ -Fields ] [ +Characters ] [ InFile [ OutFile ] ]
설명
uniq 명령은 파일에서 반복되는 줄을 지웁니다. 표준 입력이나 InFile 매개변수로 지정한 파일을 읽습니다. 먼저 이웃한 줄을 비교해, 같은 줄의 둘째 이후를 지웁니다. 중복된 줄은 붙어 있어야 합니다(uniq 전에 sort 명령으로 중복 줄을 붙여 둡니다). 마지막으로 남은 유일한 줄을 표준 출력이나 OutFile 매개변수로 지정한 파일에 씁니다. InFile과 OutFile은 서로 다른 파일이어야 합니다.
입력 파일은 텍스트 파일이어야 합니다. 텍스트 파일은 문자가 한 줄 이상으로 이뤄진 파일입니다. 줄은 길이가 2,048바이트(줄바꿈 문자 포함)를 넘거나 NULL 문자를 담을 수 없습니다.
uniq는 기본으로 줄 전체를 비교합니다.
-f Fields나-Fields를 지정하면 Fields만큼의 필드를 무시합니다. 필드는 공백 문자(<blank>) 하나 이상으로 다른 문자열과 나뉜 문자열입니다.-s Characters나-Characters를 지정하면 Characters만큼의 문자를 무시합니다.- Fields와 Characters 값은 양의 10진 정수여야 합니다.
-f가 쓰는 공백 문자와, -s가 바이트를 문자로 해석하는 방식은 현재 국가별 언어 환경이 정합니다.
uniq 명령은 잘 끝나면 0, 아니면 0보다 큰 값으로 끝납니다.
영어 원문
The uniq command deletes repeated lines in a file. The uniq command reads either standard input or a file specified by the InFile parameter. The command first compares adjacent lines and then removes the second and succeeding duplications of a line. Duplicated lines must be adjacent. (Before issuing the uniq command, use the sort command to make all duplicate lines adjacent.) Finally, the uniq command writes the resultant unique lines either to standard output or to the file specified by the OutFile parameter. The InFile and OutFile parameters must specify different files.
The input file must be a text file. A text file is a file that contains characters organized into one or more lines. The lines can neither exceed 2048 bytes in length (including any newline characters) nor contain null characters.
The uniq command compares entire lines by default. If the -f Fields or -Fields flag is specified, the uniq command ignores the number of fields specified by the Fields variable. A field is a string of characters
separated from other character strings by one or more <blank> characters. If the -s Characters or -Characters flag is specified, the uniq command ignores the number of characters specified by the Characters variable. Values specified for the Fields and Characters variables must be positive decimal integers.
The current national language environment determines the <blank> characters used by the -f flag as well as how the -s flag interprets bytes as a character.
The uniq command exits with a value of 0 if successful. Otherwise, it exits with a value greater than 0.
플래그
| 플래그 | 설명 |
|---|---|
-c |
출력 줄마다 그 줄이 입력 파일에 나온 횟수를 앞에 붙입니다. |
-d |
반복된 줄만 표시합니다. |
-f Fields |
Fields만큼의 필드를 무시합니다. Fields가 입력 줄의 필드 수보다 크면 빈 문자열로 비교합니다. -Fields와 같습니다. |
-u |
반복되지 않은 줄만 표시합니다. |
-s Characters |
Characters만큼의 문자를 무시합니다. Characters가 입력 줄의 문자 수보다 크면 빈 문자열로 비교합니다. -f와 -s를 함께 지정하면 -f로 지정한 필드 다음 필드부터 -s의 문자 수를 무시합니다. +Characters와 같습니다. |
-Fields |
Fields만큼의 필드를 무시합니다. -f Fields와 같습니다. |
+Characters |
Characters만큼의 문자를 무시합니다. -Fields와 +Characters를 함께 지정하면 -Fields로 지정한 필드 다음 필드부터 +Characters의 문자 수를 무시합니다. -s Characters와 같습니다. |
영어 원문
-c— Precedes each output line with a count of the number of times each line appeared in the input file.-d— Displays only the repeated lines.-fFields — Ignores the number of fields specified by the Fields variable. If the value of the Fields variable exceeds the number of fields on a line of input, the uniq command uses a null string for comparison. This flag is equivalent to the-Fields flag.-u— Displays only the unrepeated lines.-sCharacters — Ignores the number of characters specified by the Characters variable. If the value of the Characters variable exceeds the number of characters on a line of input, the uniq command uses a null string for comparison. If both the-fand-sflags are specified, the uniq command ignores the number of characters specified by the-sCharacters flag starting in the field following the fields specified by the-fFields flag. This flag is equivalent to the+Characters flag.-Fields — Ignores the number of fields specified by the Fields variable. This flag is equivalent to the-fFields flag.+Characters — Ignores the number of characters specified by the Characters variable. If both the-Fields and+Characters flags are specified, the uniq command ignores the number of characters specified by the+Characters flag starting in the field following the fields specified by the-Fields flag. This flag is equivalent to the-sCharacters flag.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 잘 끝났습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — The command ran successfully.
>0— An error occurred.
예제
fruit 파일에서 반복되는 줄을 지워 newfruit 파일에 저장합니다.
uniq fruit newfruit
fruit 파일의 내용이 다음과 같으면,
apples
apples
peaches
pears
bananas
cherries
cherries
uniq를 실행한 뒤 newfruit 파일의 내용은 다음과 같습니다.
apples
peaches
pears
bananas
cherries
영어 원문
To delete repeated lines in a file named fruit and save it to a file named newfruit, enter: uniq fruit newfruit
If the fruit file contains the following lines: apples apples peaches pears bananas cherries cherries
then the newfruit file will contain the following lines after you run the uniq command: apples peaches pears bananas cherries
파일
| 파일 | 설명 |
|---|---|
/usr/bin/uniq |
uniq 명령이 들어 있습니다. |
관련 명령어: sort, comm
영어 원문
- /usr/bin/uniq — Contains the uniq command.
Related reference:
- sort Command
Related information:
- comm command
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | GNU uniq |
|---|---|---|
| 줄 길이 | 2,048바이트까지 | 제한 없음 |
-Fields·+Characters 옛 형식 |
받음 | 받지 않음(-f, -s를 씀) |
AIX 5.3·6.1 문서에는 -i(대소문자 무시), -w(앞 N자만 비교), -D(중복 줄 모두 출력), -z 같은 GNU 플래그가 없습니다. 대소문자를 무시하려면 sort -f와 함께 다른 방법을 써야 합니다.