Operating System - Linux
1828459 Members
3265 Online
109978 Solutions
New Discussion

grep -A option - Illegal option issue

 
SOLVED
Go to solution
Danny Fang
Frequent Advisor

grep -A option - Illegal option issue

Hi,

I'm attempting to use the grep -A option i.e. to print the number of lines of trailing context after the matching lines.

I'm wanting to extract the values between the tags in a XML file. I've attempted the method below:
prod-cingtuna\ :/mkl/users/lows >grep -A1 -E '(>URLString<|>title<)' sample.xml
grep: illegal option -- A
Usage: grep [-c|-l|-q] [-bhinsvwx] pattern_list [file ...]
grep [-c|-l|-q] [-bhinsvwx] [-e pattern_list]... [-f pattern_file]... [file...]
grep -E [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
grep -E [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
grep -F [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
grep -F [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
prod-cingtuna\ :/mkl/users/lows >which grep
/usr/xpg4/bin/grep

prod-cingtuna\ :/mkl/users/lows>
/usr/bin/grep -A1 -E '(>URLString<|>title<)' sample.xml
/usr/bin/grep: illegal option -- A
/usr/bin/grep: illegal option -- 1
/usr/bin/grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .

However, as shown above, the grep utility didn't seem to recognize the -A option. I've used grep utilities from /usr/bin/grep and /usr/xpg4/bin/grep.

I've checked the URL http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
for the grep options and -A is a valid option.

Attached is the XML file which I'm attempting to "grep" values between the specific tag.

May I know which grep version or location of grep would have the -A option?

Thanks in advance
4 REPLIES 4
john korterman
Honored Contributor

Re: grep -A option - Illegal option issue

Hi,

the URL and -A option is for gnu grep, which you have to download and install first. You can probably find a suitable version of that at Merijn's site:
http://www.hpux.ws/merijn/

regards,
John K.
it would be nice if you always got a second chance
Steven E. Protter
Exalted Contributor
Solution

Re: grep -A option - Illegal option issue

Shalom Danny,

-A is not a valid option for the standard hp-ux grep.

I have checked egrep and it is also not valid.

You may wish to see http://www.gnu.org

They may have a grep that runs on HP-UX that meets your need.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Danny Fang
Frequent Advisor

Re: grep -A option - Illegal option issue

Hi everyone,

I've tested the grep -A option on a Linux machine and it did not produce the error "illegal option".

Thanks very much for the advice.

Danny Fang
Frequent Advisor

Re: grep -A option - Illegal option issue

Issue solved.