Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using grep and backslash to identify text containing "<"

Status
Not open for further replies.

matchum

Technical User
Nov 27, 2001
27
GB
In DOS, I can successfully grep lines containing a &quot;<&quot; symbol but the same command in Perl grep fails.

e.g.
| grep &quot;\<&quot;

I can overcome this by code but I would rather exploit the power of grep within my Perl code.
 
# make an array containing the lines you want
push @str, &quot;<kjsdkajsh>&quot;;
push @str, &quot;alksjdlaksjl&quot;;
push @str, &quot;<lakjdlsjd>&quot;;

# run grep on it
@ary = grep(/</, @str); # weed out < lines

print join &quot;\n&quot;, @ary;

this prints the lines
<kjsdkajsh>
<lakjdlsjd>

is that what you meant? Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Mike,

Your
@ary = grep(/</, @str); # weed out < lines
was the neat solution I was looking for.

I tried to backtick a command's output into an array using

| grep &quot;\<&quot;

Now I simply make a new array using your method.

Thanks
 
cool :) Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top