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
SCO unix server performance tuning forumuser7 SCO 0 03-22-2006 11:04 AM
Oracle-performance tuning kthri Shell Programming and Scripting 9 12-07-2005 12:31 PM
Performance Tuning domyalex UNIX for Dummies Questions & Answers 1 07-15-2005 10:55 AM
EXT3 Performance tuning malcom Filesystems, Disks and Memory 3 06-14-2005 11:27 PM
Performance tuning. TRUEST UNIX for Dummies Questions & Answers 1 03-21-2003 02:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2008
Amit.Sagpariya Amit.Sagpariya is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 111
Performance Tuning

Hi All,

In last one week, i have posted many questions in this portal. At last i am succeeded to make my 1st unix script.

following are 2 points where my script is taking tooooo long.

1. Print the total number of records excluding header & footer. I have found that awk 'END{print NR - 2}' <filename> will give exact result. But my file has 520 columns seperated with ^~^. while using this command, error is 'too long...... record'. so i have used like this.

a=` cut -d~ -f1 NAM2008101601.OUT |awk 'END{print NR - 2}' `

But this is taking too long.

2. i need sum of amount column. So first i have cut that column & paste it in a file. Then i have calculated sum. But it is also taking long time.

cut -d~ -f27 $FILE_NAME | cut -c2-23 > amount
tot_val=`awk '{a+=$0}END{printf "%.5f\n",a}' amount`

Appriciate if someone can help me to get alternatives which speed up this process.

Thnaks
Amit
  #2 (permalink)  
Old 10-24-2008
avis1981 avis1981 is offline
Registered User
  
 

Join Date: Oct 2008
Location: NC
Posts: 21
For the point 1, since you are assuming that there will be always header and footer, not sure why you need to read whole file NAM2008101601.OUT to get record count.

Can you try using file size and record length to get record count, subtract 2 to get data records count?

1) Take file size from ls -l NAM2008101601.OUT
2) Get the record length, if it is not constant, then use wc to get record length
3) Total records = file size/record length
4) Subtract 2 from step 3, to take header/trailer counts.

Hope this might work.
  #3 (permalink)  
Old 10-24-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
What version of awk are you using? GNU awk (gawk) has no predefined field count or record length limit.
Closed Thread

Bookmarks

Tags
performance

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 09:20 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