"리눅스 파일 특정 행 보기"의 두 판 사이의 차이

잔글
18번째 줄: 18번째 줄:
==실행예시==
==실행예시==
<source lang='dos'>
<source lang='dos'>
[root@myhost ~]# cat /etc/issue
[root@localhost ~]# cat /etc/issue
CentOS release 5.7 (Final)
CentOS release 5.7 (Final)
Kernel \r on an \m
Kernel \r on an \m


[root@myhost ~]# sed -n 2p /etc/issue
[root@localhost ~]# sed -n 2p /etc/issue
Kernel \r on an \m
Kernel \r on an \m
[root@myhost ~]# sed -n '2p;3q' /etc/issue
[root@localhost ~]# sed -n '2p;3q' /etc/issue
Kernel \r on an \m
Kernel \r on an \m
</source>
</source>


[[분류:리눅스]]
[[분류:리눅스]]

2012년 5월 4일 (금) 00:12 판

  • 리눅스 파일에서 N번째 행 출력하기
  • 리눅스 파일에서 N번째 행 보여주기
  • 리눅스 파일에서 N번째 행 가져오기

1 기본

  • test.txt 파일에서 10번행 가져오기
sed -n 10p < test.txt

2 고급

  • test.txt 파일에서 10번행 가져오기. (더 빠르게 하기)
sed -n '10p;11q' < test.txt

11번행에서 탐색을 종료하여 속도를 높힌다.

3 실행예시

[root@localhost ~]# cat /etc/issue
CentOS release 5.7 (Final)
Kernel \r on an \m

[root@localhost ~]# sed -n 2p /etc/issue
Kernel \r on an \m
[root@localhost ~]# sed -n '2p;3q' /etc/issue
Kernel \r on an \m
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}