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 11:00 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 09: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
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
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 (permalink)  
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 (permalink)  
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 (permalink)  
Old 02-12-2008
Registered User
 

Join Date: Nov 2007
Posts: 55
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 (permalink)  
Old 02-12-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,449
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 (permalink)  
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 (permalink)  
Old 02-12-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,449
till now, you have not shown your input file
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:27 PM.


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

Content Relevant URLs by vBSEO 3.2.0