Unix Arithmatic operation issue , datatype issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Arithmatic operation issue , datatype issue
# 8  
Old 02-13-2008
Quote:
Originally Posted by thambi
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.
# 9  
Old 02-13-2008
Reply..

No . .it's not working..

When I run

$ awk '{ print "last + " $0 }' hash_column_wrong.txt | bc | tail -1
syntax error on line 1,


When I run without tail..

$ awk '{ print "last + " $0 }' hash_column_wrong.txt | bc
syntax error on line 1,

When I run only , i got the result like this...

last + 0000191
last + 0000005
last + 0000001


I think format might be wrong ?.
# 10  
Old 02-13-2008
No, it means that the bc isn't the GNU one. As I mentioned, the "last" keyword is specific to GNU. You can try downloading and installing it. Run "bc --version" afterwards to make sure you're using the GNU version. You might also be asked to install the arbitrary precision library, which I recommend using.
# 11  
Old 02-13-2008
Reply..

Is it free ware?.. bc is available in my Unix version. As you said, last keyword may not compitable with bc version. Do you mean i need to download from the site?. This is impractical for me becuase .. there are lot of things need to consider as it's client production server.. If you know any other alternate way, pls let me know.
# 12  
Old 02-13-2008
Okay, if I say "GNU", yes, that means it's free.

Now, if you are using a Linux system, obviously the problem is something else (because that's what you would be using). If you have a Sun system, you can get install a CSW "package". Ask the site administrator if s/he knows about CSW/blastwave packages. Here's the link for gnu's bc: CSW - Details for gbc. Click here for the source which you can download and install.

Now, if that's not possible, you can take my original script and find out how many lines ending in "\" that bc can handle. Then you can use split to divide the file into that many lines:

Code:
split -l ?? bigfile

where ?? is the number of lines. You'll get lots of little files. Add them up individually with the awk-bc script (or another method). Then add the output up, again using awk-bc. You might have to recurse over the first step until you have a tree of sums.

Or, you can use perl. See next message.
# 13  
Old 02-13-2008
Hi ,I am using HP-UX B.11.11 ( HP unix ). If i get the freeware for HP unix, I can install the GNU bc with help of Unix admin. Please provide the link for GNU bc of HP unix.

I can't spilit the file as it's a source file which comes from source sytem. I should not touch that.. and I am pasting here my awk program to add the number.. Please look at the last "else " part which shows the addition ... in this existing code only, I need to amend the changes to get the total count with full digit rather the expontial formt..

BEGIN {
totalLatestRetailPrice = 0;
}
#
{
if (substr($0,1,7)=="HCDWC01")
{
printf "%s%58s\n", substr($0,1,28), " "
}
else
if (substr($0,1,7)=="TCDWC01")
{
printf "%s%015d%44s\n", substr($0,1,27), totalLatestRetailPrice,
" "
}
else
{

totalLatestRetailPrice += int(substr($0,14,7))
print
}

}
# 14  
Old 02-13-2008
Quote:
Originally Posted by thambi
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX email issue

Hi all, I have tried to send an email with the below script. but i am not getting the subject of the email where it is present in the simply.txt. I am using HP UNIX server. I am not sure what mistake i made in the below unix command. any help would be appreciated. cat simply.txt ... (2 Replies)
Discussion started by: arun888
2 Replies

2. Shell Programming and Scripting

If Condition Issue in UNIX

Hi I am trying to do a "IF" Condition in UNIX where we compare EACH file size in a directory with a SIZE (Parameter passed) If Each File size EXCEEDS parameter passed SIZE then we manipulate the file. Somehow the IF condition do not work ?? (is this Variable decalration issue ??) ... (9 Replies)
Discussion started by: Pete.kriya
9 Replies

3. UNIX for Advanced & Expert Users

UNIX Mount Issue

Hi, Not entirely sure if this is the right thread. Essentially, fdisk -l shows that /dev/sda is a drive (750 GB), with 1 partition at /dev/sda1 with system type "Linux". I'm pretty nooby at working with drives, but I'm pretty sure that the output of: mount /dev/sda1 /media/int Should not... (4 Replies)
Discussion started by: FreddoT
4 Replies

4. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

5. Shell Programming and Scripting

.profile issue with UNIX

Hi, There is a user in Solaris-10 zone, ora_big01. Its .profile is not getting executed due to some reason and I am not able to find that. root@trddpd-dwsq04:/# cat /etc/passwd | grep -i ora_big01 ora_big01:x:242349:220:Siebel for QA:/ccq/apps/siebel:/usr/bin/ksh root@trddpd-dwsq04:/# which ksh... (3 Replies)
Discussion started by: solaris_1977
3 Replies

6. Windows & DOS: Issues & Discussions

UNIX AD idmap issue

Hi, I'm having a nightmare of a time with this one. I've recently taken over a sys admin role and shortly after I did, the print server failed. I've had to replace the hard disk. ---don't ask about backups....there hasn't been a sys admin in post for almost a year...... Anyway, the aim, to... (0 Replies)
Discussion started by: rudigarude
0 Replies

7. Shell Programming and Scripting

Need assistance with a file issue and a terminal issue

Hello everyone, I'm in need of some assistance. I'm currently enrolled in an introductory UNIX shell programming course and, well halfway through the semester, we are receiving our first actual assignment. I've somewhat realized now that I've fallen behind, and I'm working to get caught up, but for... (1 Reply)
Discussion started by: MrMagoo22
1 Replies

8. Shell Programming and Scripting

Issue with Sort in Unix

Hi All, I am trying to sort the below data using sort command. temp.dat H|S1-511091486889|27-Jul-2011 00:00:00 H|S1-511091486823|27-Jul-2011 00:00:00 H|S1-511091486757|27-Jul-2011 00:00:00 L|S1-511091486889|1 L|S1-511091486823|1 L|S1-511091486757|1 sort -t "|" -k2 -k1 temp.dat My... (5 Replies)
Discussion started by: deepaknbk
5 Replies

9. UNIX for Dummies Questions & Answers

ISSUE and ISSUE.NET files

In LINUX(CentOS, RedHat) is there a way to have the banner statement appear before the logon instead of after the logon? In UNIX and Windows the banner appears before a person actually logs on, what I'm seeing in LINUX is that it appears after the login(ftp, telnet, SSH). Thanks (0 Replies)
Discussion started by: ejjones
0 Replies

10. Shell Programming and Scripting

UNIX variable issue

Hi all, Something funny happen with this code: EXIST=`ssh batch@190.2.332.234 'if ; then echo 0; else echo 1 ; fi'` echo $EXIST Above code will display "1". The value of remotePath is /home/batch The value of fileName is sample.txt ========================================= ... (1 Reply)
Discussion started by: suigion
1 Replies
Login or Register to Ask a Question