2014. 5. 27. 16:41

grep 검색할 단어명 -A 앞에서몇줄 -B 뒤에서몇줄

ex ) grep baby -A 3 -B 3

최근에 안 grep명령어의 좋은 기능인데,

 옵션으로 -A 검색할단어명 앞으로 지정라인, -B 검색할단어명 뒤에서 지정라인

이렇게 출력할 수 있는 것이다.



최근 열심히 듣고 있는 Chrisette Michele 의 Love is You 가사로 예제를 들어보았다.

$ cat loveisyou.txt

What's your definition of it?

Hows it make you feel?

Tell me what you say that truly makes it real

Kings and Queens, Philosophers have tried so hard to find

Tell me what it means to you dear, nevermind


Love is kind when the world is cold

Love stays strong when the fight gets old

Love's a shoulder to lean on

Love is you

Love's like the water when the well runs dry

Quench my thirst, keep me alive

*Just need one sip baby*

Love is you

Love is you, Love is you,

Love is you, Love is you


Is it possible, there is a kiss that's so divine

Or am I just a fool, is it all in my mind?

Is there something chemical

A scientist might say

Well love must be a drug

To make me feel this way


Cause Love's my permission to be who I am

No *inhibitions* cause you understand

Freedom to breathe oh baby

Love is you

Love's like a kiss when the sun goes down

Holds me tight when no one's around

Love's what I want to hold on to

Love is you


Love is you,

Love is you, Love is you,

Love is you, Love is you,

Love is you, Love is you,


Love is kind, it makes me stronger

I don't have to look no longer

You're the one I cling to

Love is you

When the chips are down

Love will stick around

I'm so glad I found

Love is you


Much as I've tried to clarify

Love's quite simple, he's just my guy

A perfect definition

Love is you

Love is you, Love is you

Love is you... is you...


검색어 날려보기 ! 두둥

$ grep baby loveisyou.txt -A 3 -B 3

Love is you

Love's like the water when the well runs dry

Quench my thirst, keep me alive

*Just need one sip baby*

Love is you

Love is you, Love is you,

Love is you, Love is you

--


Cause Love's my permission to be who I am

No *inhibitions* cause you understand

Freedom to breathe oh baby

Love is you

Love's like a kiss when the sun goes down

Holds me tight when no one's around


grep baby loveisyou.txt -A 3 -B 3


명령어를 날릴 때 색깔을 표시해 두고 싶다면,

grep baby --color=auto loveisyou.txt -A 3 -B 3

이렇게 검색하면 더 편하게 결과를 볼 수 있다.!(굿굿!)


Posted by Triany