Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The awk substring in perl script is being considered as Perl substring

Status
Not open for further replies.

siri2403

Programmer
Jul 30, 2009
1
US

Hi All!!

The below command is working fine in command prompt and shell script.But in Perl the substring along with the awk is getting overridden by the functionality of perl subsrting .
Because of which the $0 parameter in awk substring which was supposed to be interpreted as entire line from previous command is recognized as the file name of my perl script.

I can write a perl script instead of this which would solve this issue.
But i am quite curious to know about this odd behaviour.


Command

grep 050031634042163059 siritest | grep 200906011 | cut -c2-19,205-224 | awk '{ print "05 " substr($0,1,8) " " substr($0
,9,10) " " substr($0,19,10) " " substr($0,29,10) }'| awk '{ market=$1+0; account=$2+0;mobile=$3+0; noofaircalls++; airmins+=$4
; aircharge+=$5;} END {print market,account,mobile,noofaircalls,airmins,aircharge;}'


Please let me know if there is any other workaround if not substr in this case.

Thanks in advance,
Siri Chennupati
 
Perl will interpolate strings in double quotes, and as you point out $0 resolves to the name of the Perl script. Try using single quotes instead, where only backslashes will be interpolated.

But instead of shelling out to this big string of commands and pipes, maybe you should consider just using Perl to process the data?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top