bt707
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=( .*?)&(summ ary=.*)&de sc=/ && !/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,
perl -ne 'if (/(\[.*\])/ & /calid=(.*?).dtstart=(.*?)
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,
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
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
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,
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!!
Thanks again!!
ASKER
I got it to work by doing this.
perl -ne 'if (/(\[.*0000\]).*?calid=(.*
but is there a better way to do what I was trying to do above.
Thanks,