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

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:

cut -c19-20 input-file >scratch-file-1

then process the scratch file ... cheers, drl

if possible post here, sample input and output - it would be much easier for us to provide alternate solutions :slight_smile:

I'd agree with drl, but a possible alternative (if using bash) is to use parameter expansion, for example:

line="this_is_a_test"
echo "$line" | cut -c6-9
echo "${line:5:4}"

Both commands will return "is_a".