Unix Programming - problem running grep within system command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2006 > problem running grep within system command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author problem running grep within system command
jeniffer

2006-03-21, 3:17 am

system("nm -r *.o|grep -v '.o' |grep "T\|t\|U\|u" |cut -c 12-|sort|
uniq");

the problem is that if we match 1 or more strings in grep the argument
must be in quotes i.e

T\|t\|U\|u must be within quotes ...how do i escape them so that the
above works fine?

This system command is used in a PERL script.

Måns Rullgård

2006-03-21, 3:17 am

"jeniffer" <zenith.of.perfection@gmail.com> writes:

> system("nm -r *.o|grep -v '.o' |grep "T\|t\|U\|u" |cut -c 12-|sort|
> uniq");
>
> the problem is that if we match 1 or more strings in grep the argument
> must be in quotes i.e
>
> T\|t\|U\|u must be within quotes ...how do i escape them so that the
> above works fine?
>
> This system command is used in a PERL script.


\"

Also look up the -u option of sort.

--
Måns Rullgård
mru@inprovide.com
jeniffer

2006-03-21, 3:17 am

#!/usr/bin/perl

system("nm -r *.o|grep -v '.o'|grep \"T\|t\|U\|u\" |cut -c
12-|sort|uniq");

as u told ,i am doing this but it is not giving any output (no error
but no output too)....if i run this command on the command line (
without \ before " ) :
nm -r *.o|grep -v '.o'|grep "T\|t\|U\|u" |cut -c 12-|sort|uniq

it gives me the correct ouput ..whts the solution to this?

Måns Rullgård

2006-03-21, 3:17 am

"jeniffer" <zenith.of.perfection@gmail.com> writes:

> #!/usr/bin/perl
>
> system("nm -r *.o|grep -v '.o'|grep \"T\|t\|U\|u\" |cut -c
> 12-|sort|uniq");
>
> as u told ,i am doing this but it is not giving any output (no error
> but no output too)....if i run this command on the command line (
> without \ before " ) :
> nm -r *.o|grep -v '.o'|grep "T\|t\|U\|u" |cut -c 12-|sort|uniq
>
> it gives me the correct ouput ..whts the solution to this?


You need to escape these \ characters as \\, like this (single quotes
should be fine):

"... | grep 'T\\|t\\|U\\|u' | ..."

It looks like you want to match a 't' or a 'u' case insensitively. A
better way of doing this is

grep -i '[tu]'

Of course, I still thing you should be doing all this with Perl's own
facilities, since you are anyway using it.

--
Måns Rullgård
mru@inprovide.com
jeniffer

2006-03-21, 3:17 am

Thanks a lot
yes i agree but i dont know much of Perl's facilities as yet and I
gotto learn them first ...I wold surely learn them and try this way
too..

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com