Sign in to follow this  

awk in perl

Recommended Posts

Jarwulf    223

Hi, I ran across this line in a perl file


system ("awk \'\$1 == \"$label\" && \$3 <= $apex && \$4 >= $apex\{print\}\' $reference >temp_marker_$name") ==0 or die "$0 failed to awk";

Does anyone have an idea of what its doing? It seems to be printing out if some comparisons are met is as far as I figure.


Also what is with a variable name like temp_marker_$name? Aren't scalar variables supposed to start with $ and not have them in the middle? What is the purpose of the slashes in the awk command?

Share this post

Link to post
Share on other sites
Ectara    3097

The way it looks is that the backslashes are escaping characters that would be recognized as syntactically significant in perl, so that those characters are passed as-is to awk. As far as temp_marker_$name, it seems to be expanding the value of $name in-place where it is referred to in the string, sort of like Bash scripting. This would result in a name like temp_marker_foo, if $name is holding the value of "foo".


As far as the actual purpose of the awk command's arguments, someone else will have to answer.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this