본문으로 바로가기

: 파일들을 합치거나 표준출력(모니터)에 표시 할 경우에 사용하는 명령어

 

Manual page

 

 

목차

     

    0> 도표

    옵션
    기타
    -b,
    --number-nonblank
    비어있지 않은 라인에 넘버 표시
    1-2번 항목 참조
    -n,--number
    모든 라인에 넘버 표시
    1-3번 항목 참조
    -E,--show-ends
    각 라인의 끝에 $ 표시
    1-4번 항목 참조
    -s,--squeeze-blank
    여러행의 개행을 한줄로 표시
    1-6번 항목 참조
    -v,
    --show-nonprinting
    LFD && TAB 제외 특수 문자 표시 ( ^ , M-)
    1-7번항목 참조
    -T,--show-tabs
    TAB 문자를 '^I' 로 표시
    1-8번 항목 참조
    -
    standard input 에서 입력 받기
    1-11번항목 참조

    1> 옵션

    1-1> 2개의 텍스트 합치기 (d.txt + e.txt)

    d.txt

    e.txt

    $ cat d.txt e.txt > d_e.txt

    >> redirect 연산자 ('>')를 사용하면 2개의 파일을 결합해 새로운 파일을 만들수 있습니다.

    cat 다음에 연속적으로 파일이름을 적으면 (d.txt e.txt) 연속적으로 파일내용을 출력 합니다.

    1-2> -b option

    : 텅빈 라인을 제외하고 라인넘버 표시

    d.txt 에 -b option 넣으면 다음과 같습니다.

    >> nonempty (문자가 없는라인은 포함이 되지 않습니다.)

    1-3> -n option

    : 모든 출력라인에 라인넘버 표시

    >> -n option은 개행을 모두 표시해줍니다.

     

    1-4> -E option

    각라인의 끝에 $ 를 출력

    1-5> a.txt 파일을 만들고 직접 입력하기

    $ cat > a.txt or cat >> a.txt

    > : 기존파일과 상관없이 무조건 파일을 새로 생성해 줍니다.

    >> : 기존 a.txt 파일이 없으면 생성하고 파일이 존재하면 마지막에 데이타를 추가해 줍니다.

    "> or >> "을 사용해 입력후 종료시에는 Ctrl + d , Ctrl +c 를 눌러 줍니다.

    1-6> -s option (--squeeze-blank )

    : suppress repeated empty output lines

    >> 여러행의 개행을 한줄로 표시 (suppress repeated empty output lines)

     

     

     

    1-7> -v option ( --show-nonprinting)

    : use ^ and M- notation, except for LFD and TAB

    1-8> -T option (--show-tabs)

    : display TAB 문자를 ^I 로 표시합니다.

    $ cat a.txt
    hello in a.txt
    1
    12
    123
    1234
    12345
    123456
            1   >> use tab
            12  >> use tab
    123
    1234
    12345
    end
    
    >> tab 사용시 ^I 를 표시해 줍니다.
    $ cat -T a.txt
    hello in a.txt
    1
    12
    123
    1234
    12345
    123456
    ^I1   >> use tab
    ^I12  >> use tab
    123
    1234
    12345
    end

     

    1-9> --help

     

    $ cat --help
    Usage: cat [OPTION]... [FILE]...
    Concatenate FILE(s), or standard input, to standard output.
    
      -A, --show-all           equivalent to -vET
      -b, --number-nonblank    number nonempty output lines, overrides -n
      -e                       equivalent to -vE
      -E, --show-ends          display $ at end of each line
      -n, --number             number all output lines
      -s, --squeeze-blank      suppress repeated empty output lines
      -t                       equivalent to -vT
      -T, --show-tabs          display TAB characters as ^I
      -u                       (ignored)
      -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
          --help     display this help and exit
          --version  output version information and exit
    
    With no FILE, or when FILE is -, read standard input.
    
    Examples:
      cat f - g  Output f's contents, then standard input, then g's contents.
      cat        Copy standard input to standard output.

     

     

    1-10> --version

    $ cat --version
    cat (GNU coreutils) 8.21
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    Written by Torbjörn Granlund and Richard M. Stallman.

     

    1-11> - 옵션 (f - g)

    : Standard input 에서 읽기

    >> a.txt 와 b.txt 파일 출력하기
    $ head -v a.txt b.txt
    ==> a.txt <==
    1
    2
    3
    4
    5
    6
    7
    8
    
    ==> b.txt <==
    4
    5
    6
    7
    
    >> a.txt 와 출력후 stand input 에서 값을 받고 b.txt 출력 하기
    $ cat a.txt - b.txt > o.txt
    hello
    
    $ cat o.txt
    1
    2
    3
    4
    5
    6
    7
    8
    
    hello
    4
    5
    6
    7
    
    >> echo 에서 입력된 데이타를 a.txt 와 b.txt 사이에 넣고 p.txt 에 저장하기
    $ echo "hi" | cat a.txt - b.txt > p.txt
    $ cat p.txt
    1
    2
    3
    4
    5
    6
    7
    8
    
    hi
    4
    5
    6
    7

     

     

     

     

     

     

     

    그럼 오늘도 화이팅입니다.

     

     

     

     

     

    반응형