I had to calculate sum of a particular column from a huge data file. So I wrote a small bc script like this
----sum.bc-----
sum = 0
while(1)
{
c = read()
if ( c == q )
{
break
}
sum += c
}
sum
quit
----sum.bc-----
and invoked it like this
cat data.dat | awk -F '"' '{print $24}END{print "q"}' | bc -q -l sum.bc
This worked perfectly on my home system which is a linux. But when I did the same in Solaris which had a older bc that dude didn't understand my modern lingo. So I had to abandon the bc script.
So I thought I will just produce the entire sum string with numbers and "+" signs and pump it to bc, like this.
cat data.dat | awk -F '"' '{print $24}' | awk '{printf "%s+",$1}END{print "0"}' | bc -l
Again this worked with my small sample file but bc ran out of internal space when I fed a huge data file. Finally I had to abandon the specialized tool for calculation and fall back on my usual file processor awk to take over the job of the calculator.
cat data.dat | awk -F '"' '{print $24}' | awk '{s += $1}END{print s}'
Well..well ...I fed more than a Gig of data to this small wonder in that old dinky Solaris machine and it worked like a charm.
Thursday, July 20, 2006
Tuesday, July 18, 2006
Sendmail and its aversion to upper case
I know lower case rules the Unix world. But at my home for some weird issue with samba shares I had to create a user with upper case "Bob". And I created my fetchmailrc with a very simple no nonsense configuration.
poll mail.X.org proto pop3
user bobnap is Bob here
options keep ssl
When I asked fetchmail to do its job, it did everything correctly and handed over the fetched mail to my local sendmail. Which puked on everything with the following message...
1 message for at mail.X.org (774 octets).
reading message bobnap@mail.X.org:1 of 1 (774 octets) fetchmail: SMTP error: 550 5.1.1... User unknown
fetchmail: mail from MAILER-DAEMON@localhost bounced to bobnap@X.org
fetchmail: can't even send to Bob!
not flushed
Intrigued by this I tried to mail myself. The mail ended dead in the "dead.letter".
$ mailx -s "Tot" Bob < /dev/null
Null message body; hope that's ok
$ /home/Bob/dead.letter... Saved message in /home/Bob/dead.letter
I checked and rechecked my sendmail configuration, its aliases etc. Everything seemed alright. Then I logged in as a another user "naper" in my system and tried mailx. Magically everything worked great. Then only I realized the fact that sendmail didn't like the upper case in "Bob" and to confirm that I just edited the passwd files to make it all lower case and sure enough...bob is getting his mails now!
What a strange ugly little devil!
poll mail.X.org proto pop3
user bobnap is Bob here
options keep ssl
When I asked fetchmail to do its job, it did everything correctly and handed over the fetched mail to my local sendmail. Which puked on everything with the following message...
1 message for
reading message bobnap@mail.X.org:1 of 1 (774 octets) fetchmail: SMTP error: 550 5.1.1
fetchmail: mail from MAILER-DAEMON@localhost bounced to bobnap@X.org
fetchmail: can't even send to Bob!
not flushed
Intrigued by this I tried to mail myself. The mail ended dead in the "dead.letter".
$ mailx -s "Tot" Bob < /dev/null
Null message body; hope that's ok
$ /home/Bob/dead.letter... Saved message in /home/Bob/dead.letter
I checked and rechecked my sendmail configuration, its aliases etc. Everything seemed alright. Then I logged in as a another user "naper" in my system and tried mailx. Magically everything worked great. Then only I realized the fact that sendmail didn't like the upper case in "Bob" and to confirm that I just edited the passwd files to make it all lower case and sure enough...bob is getting his mails now!
What a strange ugly little devil!
Subscribe to:
Posts (Atom)