The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
Implementing "Time Limited, Trial" version of my program the_learner UNIX for Advanced & Expert Users 4 06-07-2007 02:46 AM
how could i make a program mixed with many "|", "<" and ">" strugglingman High Level Programming 2 04-29-2006 05:11 AM
Any limitations to the "top" command? lawadm1 UNIX for Dummies Questions & Answers 6 07-11-2002 07:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-12-2008
Registered User
 

Join Date: Feb 2008
Posts: 14
Post substr() limitations in "AWK" program..!!!

Is there any limitation for the function substr()
Iam trying to assign some 11 digit number value to variable. And printing the variable. This is printing invalid values.

cur_val=substr($0,36,11);
printf "Current Value is: %d\n",cur_val


I tried till 9 digits length, it was working fine. If I select more than 10 digits problem occurs.

What could be the problem and what are the alternatives in awk script.

This would be helpful for all...

Thanks in advance / Lokiman
Reply With Quote
Forum Sponsor
  #2  
Old 02-12-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
substr will return the substring of the string provided. I am not clear wether you want to use this function or the index function
Reply With Quote
  #3  
Old 02-12-2008
Registered User
 

Join Date: Feb 2008
Posts: 14
This substr() function Iam using inside the 'awk' script to assign current record position values...
Reply With Quote
  #4  
Old 02-12-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
It may be because of %d in printf, try %ld in printf

my be in ur unix version %d is having 9 digit limitation, but for me both %d and %ld is giving same result. Just try
Reply With Quote
  #5  
Old 02-12-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by lokiman View Post
Is there any limitation for the function substr()
Iam trying to assign some 11 digit number value to variable. And printing the variable. This is printing invalid values.

cur_val=substr($0,36,11);
printf "Current Value is: %d\n",cur_val


I tried till 9 digits length, it was working fine. If I select more than 10 digits problem occurs.

What could be the problem and what are the alternatives in awk script.

This would be helpful for all...

Thanks in advance / Lokiman
that statement says get the substring starting from position 36. make sure your $0 has more positions than that.
Reply With Quote
  #6  
Old 02-12-2008
Registered User
 

Join Date: Feb 2008
Posts: 14
Question $0 has 120 charecter length.

$0 has 120 charecter length.

I think this could be the limitation with the '%d'.
Are there any other reasons and alternatives?

Thanks
Reply With Quote
  #7  
Old 02-12-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
till now, you have not shown your input file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0