[Linux] 파일 출력, 정렬, 중복 행 제거

2023. 3. 15. 16:21CS/Linux

  • head(tail) -n 3 [파일이름]
    • 지정한 파일 앞, 뒤로 n행 출력
yoonho@DESKTOP-QJCBDQD:~/workspace$ cat test_head.txt
a
b
c
yoonho@DESKTOP-QJCBDQD:~/workspace$ head -n 2 test_head.txt
a
b
yoonho@DESKTOP-QJCBDQD:~/workspace$ tail -n 2 test_head.txt
b
c
  • sort [파일이름]
    • 파일 행 단위 정렬
    • -r : 내림차순
    • -n : 숫자 오름차순 
yoonho@DESKTOP-QJCBDQD:~/workspace$ cat test_sort.txt
c
a
b
d
yoonho@DESKTOP-QJCBDQD:~/workspace$ sort test_sort.txt
a
b
c
d

yoonho@DESKTOP-QJCBDQD:~/workspace$ cat test_sort_n.txt
2
3
4
1
yoonho@DESKTOP-QJCBDQD:~/workspace$ sort -n test_sort_n.txt
1
2
3
4
  • uinq [파일이름]
    • 중복된 내용의 행이 연속으로 있는 경우 중복 제거
    • [명령어] [파일이름] | uniq : 해당 명령어 실행 전 중복 제거
yoonho@DESKTOP-QJCBDQD:~/workspace$ cat test_uniq.txt
11
22
33
33
44
yoonho@DESKTOP-QJCBDQD:~/workspace$ cat test_uniq.txt | uniq
11
22
33
44