perl and awk
Anonymous Monk
created: 2006-03-09 00:25:54
hi, I have a regular command that runs fine from the command line. find . -type f|xargs grep "Login*" 2>/dev/null | grep "2006-03-08" | perl -nae 'print "$F0 $F8\n"' When I run the above command I can get the 1st and 8th column. But when I put the command in a script, the command doesnt work. Please give any suggestions. Thank you
Re: perl and awk
created: 2006-03-09 00:42:49

perl -nae '...'
is equivalent to
perl -e 'while (<>) { @F = split(" "); ... }'

Does that help? I'm not sure what you are trying to do.

Perl command lin switches are documented in perlrun.

Re: perl and awk
created: 2006-03-09 01:15:54

I believe you might benefit from reading node 120752.

HTH,

planetscape
Re: perl and awk
created: 2006-03-09 01:52:05
Why do you refer to "awk" in the title of your post?

When you say "put the command in a script", do you mean that you have a perl script that contains something like this?

my $cmd = </dev/null | grep "2006-03-08" | perl -nae 'print "$F[0] $F[8]\n"'
CMD

system( $cmd );

If so, I'm sure there is a better way to do whatever you're trying to accomplish. As it is, you are probably getting fouled up by improper or inadequate escaping of "magic" characters and/or some unexpected limits on "quoting within 'quoted' strings". But I'm only guessing, because the only diagnostic info you gave us is "the command doesn't work". (I know from experience that mixing magic characters and multiple layers of quoting within a system call is awfully risky and prone to failure.)

Here's a suggestion: give us more detail about what you actually did, and about what is really meant by "doesn't work" -- e.g. the error messages and or output that you get. (While you're at it, learn about using <code> tags in your posts.)

BTW, you said that print "$F[0] $F[8]\n" gives you the "1st and 8th" column -- I think you meant the "1st and 9th".

perlmonks.org content © perlmonks.org and Anonymous Monk, graff, ikegami, planetscape

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03