paste 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-paste
핵심 정리
- 여러 파일의 같은 줄끼리 탭으로 이어 붙여 표준 출력에 씁니다(병렬 합치기). 파일을 세로로 잇는
cat의 짝입니다. -s는 한 파일의 줄들을 가로로 잇습니다(직렬 합치기).-d 목록으로 구분자를 바꿉니다. 문자가 여럿이면 차례로 돌려 씁니다.\n,\t,\\,\0(빈 문자열)을 쓸 수 있습니다.- 파일 이름 자리에
-를 쓰면 표준 입력을 읽습니다.ls | paste - - - -는 네 열로 보여 줍니다. - 입력 파일은 32,767개(
OPEN_MAX)까지 받습니다. - AIX 5.3과 6.1 문서의 내용이 같습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전 내용 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4 |
| 파일 | /usr/bin/paste |
| 관련 명령어 | cut, cat, pr |
목적
여러 파일의 줄을 이어 붙입니다.
영어 원문
Joins the lines of different files.
구문
paste [ -s ] [ -d List ] File1 ...
설명
paste 명령은 명령줄에 지정한 파일들에서 입력을 읽습니다. 파일 이름으로 -(빼기)를 쓰면 표준 입력을 읽습니다. 주어진 입력 파일들의 대응하는 줄을 이어 붙여 표준 출력에 씁니다.
기본으로 파일 하나를 열 하나로 보고 탭 문자로 가로로 잇습니다(병렬 합치기). 파일을 세로로, 곧 한 파일 뒤에 다른 파일을 잇는 cat 명령의 짝이라고 생각하면 됩니다.
-s 플래그를 쓰면 한 입력 파일의 이어지는 줄들을 합칩니다(직렬 합치기). 이 줄들도 기본으로 탭 문자로 이어집니다.
참고:
paste는 입력 파일을 32,767개(OPEN_MAX상수)까지 받습니다.pr -t -m명령은paste와 비슷하게 동작하지만, 보기 좋은 쪽 배치를 위해 빈칸, 탭, 줄을 더 넣습니다.- 입력 파일은 텍스트 파일이어야 하지만 줄 길이에는 제한이 없습니다.
영어 원문
The paste command reads input from the files specified on the command line. The command reads from standard input if a - (minus sign) appears as a file name. The command concatenates the corresponding lines of the given input files and writes the resulting lines to standard output.
By default, the paste command treats each file as a column and joins them horizontally with a tab character (parallel merging). You can think of the paste command as the counterpart of the cat command (which concatenates files vertically, that is, one file after another).
With the -s flag, the paste command combines subsequent lines of the same input file (serial merging). These lines are joined with the tab character by default.
Notes:
The paste command supports up to 32767 input files (the
OPEN_MAXconstant).The action of the pr
-t -mcommand is similar to that of the paste command, but creates extra spaces, tabs, and lines for a nice page layout.Input files should be text files, but may contain an unlimited number of line lengths.
플래그
| 플래그 | 설명 |
|---|---|
-d List |
출력에서 대응하는 줄 사이의 구분자를 List의 문자 하나 이상으로 바꿉니다(기본은 탭). List에 문자가 여럿이면 출력 끝까지 차례로 되풀이해 씁니다. 병렬 합치기에서 마지막 파일의 줄은 List의 문자가 아니라 늘 줄바꿈으로 끝납니다. 셸에서 특별한 뜻이 있는 문자는 따옴표로 감쌉니다. |
-s |
첫 파일의 이어지는 줄들을 가로로 합칩니다. 파일 하나를 끝까지 처리한 뒤 다음 파일을 시작합니다. 한 파일의 줄을 다 합치면 줄을 바꾸고 다음 입력 파일의 줄을 합치는 식으로 나머지 파일을 하나씩 처리합니다. -d를 쓰지 않으면 탭으로 나눕니다. List와 상관없이 파일의 마지막 문자는 줄바꿈이 됩니다. |
-d의 List에 쓸 수 있는 특수 문자:
| 문자 | 뜻 |
|---|---|
\n |
줄바꿈 |
\t |
탭 |
\\ |
백슬래시 |
\0 |
빈 문자열(NULL 문자가 아님) |
| c | 확장 문자 |
영어 원문
-dList — Changes the delimiter that separates corresponding lines in the output with one or more characters specified in the List parameter (the default is a tab). If more than one character is in the List parameter, then they are repeated in order until the end of the output. In parallel merging, the lines from the last file always end with a new-line character instead of one from the List parameter. The following special characters can also be used in the List parameter:\nNew-line character\tTab\\Backslash\0Empty string (not a null character) c An extended character You must put quotation marks around characters that have special meaning to the shell.-s— Merges subsequent lines from the first file horizontally. With this flag, the paste command works through one entire file before starting on the next. When it finishes merging the lines in one file, it forces a new line and then merges the lines in the next input file, continuing in the same way through the remaining input files, one at a time. A tab separates the lines unless you use the-dflag. Regardless of the List parameter, the last character of the file is forced to be a new-line character.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 잘 끝났습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — Successful completion.
>0— An error occurred.
예제
- 여러 열의 데이터를 이어 붙입니다.
names파일을 첫 열로,places파일을 둘째 열로,dates파일을 셋째 열로 하는npd파일을 만듭니다.
paste names places dates > npd
세 파일의 내용이 다음과 같으면(왼쪽부터 names, places, dates),
rachel New York February 5
jerry Austin March 13
mark Chicago June 21
marsha Boca Raton July 16
scott Seattle November 4
npd 파일의 줄마다 이름, 장소, 날짜가 탭으로 나뉘어 들어갑니다. 탭 위치가 8열마다라서 열이 늘 맞지는 않습니다.
- 탭이 아닌 문자로 열을 나눕니다.
!와@를 번갈아 열 구분자로 씁니다.
paste -d"!@" names places dates > npd
rachel!New York@February 5
jerry!Austin@March 13
mark!Chicago@June 21
marsha!Boca Raton@July 16
scott!Seattle@November 4
- 표준 입력을 여러 열로 표시합니다. 현재 디렉터리를 네 열로 나열합니다.
-(빼기)마다 표준 입력에서 읽은 데이터로 열을 하나씩 만들어, 첫 줄은 첫 열에, 둘째 줄은 둘째 열에 넣는 식입니다.
ls | paste - - - -
다음 명령도 같습니다. 표준 입력의 줄들로 쪽을 가로질러 열을 채웁니다. -d"\t\t\t\n"은 앞의 세 열 뒤에는 탭(\t)을, 넷째 열 뒤에는 줄바꿈(\n)을 넣습니다. -d가 없으면 paste -s -는 입력 전체를 열 사이에 탭을 둔 한 줄로 보여 줍니다.
ls | paste -d"\t\t\t\n" -s -
영어 원문
- To paste several columns of data together, enter:
paste names places dates > npd
This creates a file named npd that contains the data from the names file in one column, the places file in another, and the dates file in a third. If the names, places, and dates file look like: names places dates rachel New York February 5 jerry Austin March 13 mark Chicago June 21 marsha Boca Raton July 16 scott Seattle November 4
then the npd file contains: rachel New York February 5 jerry Austin March 13 mark Chicago June 21 marsha Boca Raton July 16 scott Seattle November 4
A tab character separates the name, place, and date on each line. These columns do not always line up because the tab stops are set at every eighth column.
- To separate the columns with a character other than a tab, enter:
paste -d"!@" names places dates > npd
This alternates ! and @ as the column separators. If the names, places, and dates files are the same as in example 1, then the npd file contains:
rachel!New York@February 5
jerry!Austin@March 13
mark!Chicago@June 21
marsha!Boca Raton@July 16
scott!Seattle@November 4
- To display the standard input in multiple columns, enter:
ls | paste - - - -
This lists the current directory in four columns. Each - (minus) tells the paste command to create a column containing data read from the standard input. The first line is put in the first column, the second line in the second column, and so on. This is equivalent to:
ls | paste -d"\t\t\t\n" -s -
This example fills the columns across the page with subsequent lines from the standard input. The -d"\t\t\t\n" defines the character to insert after each column: a tab character (\t) after the first three columns, and a new-line character (\n) after the fourth. Without the -d flag, the paste -s - command would display all of the input as one line with a tab character between each column.
파일
| 파일 | 설명 |
|---|---|
/usr/bin/paste |
paste 명령이 들어 있습니다. |
관련 명령어: pr, cat, cut
영어 원문
- /usr/bin/paste — Contains the paste command.
Related reference:
- pr Command
Related information:
- cat command
- cut command
- Files command
- Input and output redirection
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | GNU paste |
|---|---|---|
| 입력 파일 수 | 32,767개(OPEN_MAX)까지 |
열 수 있는 파일 수까지 |
AIX 5.3·6.1 문서에는 -z(NUL로 끝나는 줄), --serial·--delimiters 같은 긴 옵션이 없습니다.