The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix:mail sending issue..pls help me soon bobprabhu UNIX for Dummies Questions & Answers 2 02-01-2008 05:44 AM
Unix Login Issue freakygs UNIX for Advanced & Expert Users 1 01-16-2008 08:21 AM
Issue with Unix cat command RcR Shell Programming and Scripting 13 10-31-2007 05:54 AM
Unix command mmin issue Mohee UNIX for Dummies Questions & Answers 1 08-30-2007 11:41 PM
Unix in a Windows environment issue Aisha Sturkey UNIX for Dummies Questions & Answers 6 05-02-2005 10:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-13-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
Quote:
Originally Posted by thambi View Post
When I run the below command

awk '{ print $0 " +\\" }' hash_column_wrong.txt | bc

I got below exception..

bundling space exceeded on line 1,
bundling space exceeded on line 1,
bundling space exceeded on line 1,

is it due to \n character that occurs end of the line?.
Sounds like bc can't handle the huge line size. try this:
Code:
awk '{ print "last + " $0  }' hash_column_wrong.txt | bc  | tail -1
This prints out a sub-result for each line. The only catch is that "last" is a GNU extension.
  #2 (permalink)  
Old 02-13-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
Quote:
Originally Posted by thambi View Post
a=2147483647
expr $a + 2

for this i need to get the right result rather than -ve value.
I'm on a 64-bit machine, and awk and Perl seem to work fine here. I don't have access to a 32-bit machine at the moment. But try it with perl:

Code:
#!/usr/bin/env perl -w
$bc_lines=100;

local $maxint=int(2*(2**30 - 1)+1);
my $a=0;
my @subresults;

while ($_=<>) {
  chop;
  if ($maxint - int($_) < $a) {
    push @subresults, $a;
    $a=0;
  }
  $a+=int($_);
}
while (scalar(@subresults)) {
  print join("+\\\n",splice(@subresults,0,$bc_lines),"0\n");
}
Now run this script, pipe through bc *recursively* until there is only one line left. For example:

Code:
cp bigfile.txt outfile.txt 
while [ ! -f outfile.txt -o `grep -c ^ outfile.txt` -gt 1 ]; do 
  perl test.pl  outfile.txt  |bc >outfile.$$ ; 
  mv outfile.$$ outfile.txt; 
  echo "Subcalc complete" >&2; 
done ; 
cat outfile.txt
If bc complains with the same error, lower 100 to, say, 50. Keep cutting in half till no more complaints.

the GNU bc link is in my previous post.
  #3 (permalink)  
Old 02-13-2008
thambi thambi is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 32
Sorry, I have not worked on Perl scripting.. it's new to me... I feel GNU bc method will be ok for me.. if you guide me the installation way, i can probably try with that method.....
  #4 (permalink)  
Old 02-13-2008
thambi thambi is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 32
And also I have just found that my machine is 64 bit..

$ getconf KERNEL_BITS
64

now is there anyway to get my result?
  #5 (permalink)  
Old 02-13-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
Quote:
Originally Posted by thambi View Post
And also I have just found that my machine is 64 bit..

$ getconf KERNEL_BITS
64

now is there anyway to get my result?

Depends on if the programs are compiled in 64-bit. Try
Code:
file `which bc` `which awk` `which perl`
Is it a 64-bit or 32-bit executable? (You might have to find the paths manually).

For installing bc, you'll have to go to the home page, whose link I provided, and follow the steps. You'll probably need the sysadmin's help, but in theory, you can do something like:

Code:
gunzip -c gbc-*tgz | tar xf - 
cd gbc????
./configure --prefix=$HOME
make install
  #6 (permalink)  
Old 02-13-2008
thambi thambi is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 32
I got the below result...

$ file `which bc` `which awk` `which perl`
/usr/bin/bc: PA-RISC1.1 shared executable dynamically linked
/usr/bin/awk: PA-RISC1.1 shared executable dynamically linked
/usr/bin/perl: PA-RISC1.1 shared executable dynamically linked -not stripped
$


Meantime, I just waiting for my Unix admin's response to install GNU bc. If i install GNU bc, current version bc will be affected. I mean GNU bc having all the features ?
Closed Thread

Bookmarks

Tags
bc, big numbers, gawk, sum by column

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0