Link to home
Start Free TrialLog in
Avatar of bt707
bt707Flag for United States of America

asked on

perl print question

I have this command that give me what I need but can't get the print out right.

perl -ne 'if (/(\[.*\])/ & /calid=(.*?).dtstart=(.*?)&.*dtend=(.*?)&(summary=.*)&desc=/ && !/uid=/) {print "$1\t$2\t$3\t$4\t$5\n"}' log.txt


problem here is always prints the $1 $2.... starting with the second set of  /..../   what do I need to do if I want to print  from both  

example: print $1 and $2 from this pattern
      '/.....(....)/  &  /...(...)/'


Thanks,

Avatar of bt707
bt707
Flag of United States of America image

ASKER


I got it to work by doing this.

perl -ne 'if (/(\[.*0000\]).*?calid=(.*?).dtstart=(.*?)&.*dtend=(.*?)&(summary=.*)&desc=/ && !/uid=/) {print "$1\t$2\t$5\t$3\t$4\n"}'  log.txt

but is there a better way to do what I was trying to do above.


Thanks,
Avatar of ozo
what would you consider to be better?
The main differerence between what you were saying you were trying to do and what you did is that what you did is that what dyou did won't match if the (\[.*0000\]) doed not come before the calid, and you print in a different order
Avatar of bt707

ASKER

I got that part sorted out, I had just posted this as a example but had a few things out of line here.

I figure the part out I needed for the search but what I was now trying to do was to see how you could print out the
$1 and $2 if you had them in a search such as  '/.....(....)/  &  /...(...)/'  everytime I try this it always ignores one of them

works fine if I have all the $n between /......./   but when I have a command with a  /...../ &  /....../ in it I can't get it to work.
so trying to figure out how you would print out $1 and $2 in a command such as this

perl -ne 'print  "$1\t$2\n" if /someword(.*?)someword/  & /someword(.*?)someword/' file.txt


Hope that shows what I'm trying to figure out.


Thanks,

SOLUTION
Avatar of mjcoyne
mjcoyne

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bt707

ASKER

ok, Thanks to everyone for the explaination, now I see what the problem is and why it's doing what it is and thanks to jmcq for the good example of how to work this out.


Thanks again!!