"리눅스 문자열 매칭 행번호 확인"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
잔글 (봇: 자동으로 텍스트 교체 (-==참고 자료== +==참고==))
49번째 줄: 49번째 줄:
*[[행 번호]]
*[[행 번호]]


==참고 자료==
==참고==
*http://stackoverflow.com/questions/7103531/how-to-get-the-part-of-file-after-the-line-that-matches-grep-expression-first
*http://stackoverflow.com/questions/7103531/how-to-get-the-part-of-file-after-the-line-that-matches-grep-expression-first


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

2017년 7월 11일 (화) 04:16 판

match string and get line number
grep 행번호 확인
리눅스 문자열 매칭 행번호 확인
get line number of first matching
리눅스 첫번째 매칭 행번호 확인
get line number of last matching
리눅스 마지막 매칭 행번호 확인

1 여러 행

명령어
grep -n 문자열 파일
grep -n 문자열 파일 | cut -d: -f1
grep -n 문자열 파일 | awk '{print $1}' FS=":"
실행예시
[root@zetawiki ~]# grep -n logvol /root/anaconda-ks.cfg
22:#logvol /home --fstype=ext4 --name=lv_home --vgname=VolGroup --grow --size=100
23:#logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
24:#logvol swap --name=lv_swap --vgname=VolGroup --grow --size=1024 --maxsize=6064
[root@zetawiki ~]# grep -n logvol /root/anaconda-ks.cfg | cut -d: -f1
22
23
24

2 첫번째 매칭

[root@zetawiki ~]# grep -n logvol /root/anaconda-ks.cfg | cut -d: -f1 | head -1
22

3 마지막 매칭

[root@zetawiki ~]# grep -n logvol /root/anaconda-ks.cfg | cut -d: -f1 | tail -1
24

4 같이 보기

5 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}