Cut too slow


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut too slow
# 1  
Old 05-10-2008
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  
Old 05-10-2008
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  
Old 05-11-2008
Quote:
Originally Posted by pukars4u
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 Smilie
# 4  
Old 05-11-2008
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".
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

4. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

5. Shell Programming and Scripting

File processing is very slow with cut command

Dear All, I am using the following script to find and replace the date format in a file. The field18 in the file has the following format: "01/26/2010 11:55:14 GMT+04:00" which I want to convert into the following format "20100126115514" for this purpose I am using the following lines of codes:... (5 Replies)
Discussion started by: bilalghazi
5 Replies
Login or Register to Ask a Question