Shell scripting or something better?
May 9, 2008 2:19 PM Subscribe
Faster techniques for grabbing lines of a file and doing text manipulation and arithmetic via shell (or other) scripting?
1. Are there faster ways to grab lines of a text file?
Currently I use while read line and sed -n #p filename in bash and csh scripts to grab lines of a file I'm interested in. This seems slow. Are there better (faster) ways to get the line of a file, or to iterate through specified ranges of lines in a file?
2. Are there faster ways than awk to grab values in a line?
Let's say I have the tab-delimited line:
abc 123 345 0.52
What I'd like to do is get the second and third values, or the fourth value, as quickly as possible. Is there a better way than awk? Will a perl or other interpreted language script run faster than a shell script for scraping values from a text file?
3. Arithmetic with bash?
I've been doing $((${value1}+${value2})) for integer arithmetic and calc ${value1} / ${value2} for floating point arithmetic within bash. Will I gain a performance benefit from switching over my code from bash to another shell script language, or to another interpreted language entirely?
Thanks for any and all tips and tricks.
posted by Blazecock Pileon to computers & internet (20 answers total) 2 users marked this as a favorite
posted by wongcorgi at 2:42 PM on May 9, 2008