Operating System - HP-UX
1829132 Members
2063 Online
109986 Solutions
New Discussion

Re: How to make grep to match start of line.

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

How to make grep to match start of line.

Hi All,

I am using this command
/opt/ignite/binpa/print_manifest.
It is showing very long output.

I want to search for string "HP" but, it should be at the start of the line only.

How can i use grep in this case?

Thanks & regards,
Prasad
7 REPLIES 7
Arunvijai_4
Honored Contributor

Re: How to make grep to match start of line.

Hi Prasad,

You can rather store output of /opt/ignite/binpa/print_manifest to a file and do a search with "vi". print_manifest gives a detailed output of all neccessary stuffs.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
RAC_1
Honored Contributor

Re: How to make grep to match start of line.

/opt/ignite/binpa/print_manifest | grep '^HP'

grep -i '^HP' ->
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: How to make grep to match start of line.

/opt/ignite/binpa/print_manifest | grep '^HP'

grep -i '^HP' -> To ignore case
There is no substitute to HARDWORK
Arunvijai_4
Honored Contributor

Re: How to make grep to match start of line.

Hi Prasad,

# /opt/ignite/binpa/print_manifest | grep -i '^HP'

Should be useful. But, look at everything in detail like,

# /opt/ignite/binpa/print_manifest | more


-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: How to make grep to match start of line.

/opt/ignite/binpa/print_manifest | grep -E "^HP"

will give it.

^ - to give start of line.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor
Solution

Re: How to make grep to match start of line.

There is a possiblity to have spaces infront of HP in the line start. To get that also then use as,

/opt/ignite/binpa/print_manifest | grep -E "^[ ]*HP"

Will help.

You can use awk or perl or sed too.

--
Muthu
Easy to suggest when don't know about the problem!
Prasad Joshi
Regular Advisor

Re: How to make grep to match start of line.

Hi All,

Thanks for instant replay.

This did the job
/opt/ignite/binpa/print_manifest | grep -E "^[ ]*HP"

Special thanks to Muthukumar


Thanks & regards.
Prasad