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
scp is slow tomstone_98 UNIX for Dummies Questions & Answers 1 07-26-2007 09:33 AM
Slow FTP & SMB rockboles UNIX for Dummies Questions & Answers 4 12-11-2005 07:52 PM
ls -l over NFS slow keelba UNIX for Advanced & Expert Users 3 01-21-2004 08:17 AM
CPU slow down Henrik UNIX for Dummies Questions & Answers 4 11-21-2002 05:26 AM
slow ftp suntan UNIX for Dummies Questions & Answers 3 07-16-2001 09:42 AM

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 05-10-2008
pukars4u pukars4u is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 7
Cut too slow

Hi I am using a cut command in the script which is slowing down the performance of the script .can anyone suggest the other ways of doing the same cut command

Record_Type=`echo "$line" | cut -c19-20`
*******this is slowing down*********
i have 4 more cut commands
2 in one loop and 2 in inner looop

can I replace cut with anyother functionalities
Do help me on this thanks
  #2 (permalink)  
Old 05-10-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi.

It looks like you are processing one line at time. That will be inherently slow, because you will be loading cut for each line. Let cut process the entire file -- try to re-think your method on a file-based idea, preferably with a pipe, or, at the very least, writing an intermediate file like:
Code:
cut -c19-20 input-file >scratch-file-1
then process the scratch file ... cheers, drl
  #3 (permalink)  
Old 05-11-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Quote:
Originally Posted by pukars4u View Post
Hi I am using a cut command in the script which is slowing down the performance of the script .can anyone suggest the other ways of doing the same cut command

Record_Type=`echo "$line" | cut -c19-20`
*******this is slowing down*********
i have 4 more cut commands
2 in one loop and 2 in inner looop

can I replace cut with anyother functionalities
Do help me on this thanks
if possible post here, sample input and output - it would be much easier for us to provide alternate solutions
  #4 (permalink)  
Old 05-11-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
I'd agree with drl, but a possible alternative (if using bash) is to use parameter expansion, for example:

Code:
line="this_is_a_test"
echo "$line" | cut -c6-9
echo "${line:5:4}"
Both commands will return "is_a".
Sponsored Links
Closed Thread

Bookmarks

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 06:10 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