Subscribewhile 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?awk to grab values in a line?abc 123 345 0.52awk? Will a perl or other interpreted language script run faster than a shell script for scraping values from a text file?bash?$((${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?
#!/bin/bash
acc=1
while read line; do acc=$((1000000 + $line)); done
#!/usr/bin/env python
import sys
acc = 1
for line in open(sys.argv[1], 'r'):
acc = 1000000 + int(line) # Indent this line
mayu:~ mark$ time ./addup.sh < rndlines
real 0m12.396s
user 0m9.873s
sys 0m1.752s
mayu:~ mark$ time ./addup.py rndlines
real 0m0.331s
user 0m0.258s
sys 0m0.033s
mayu:~ mark$ time awk '{ print $3 }' rndtabs > /dev/null
real 0m0.928s
user 0m0.847s
sys 0m0.022s
mayu:~ mark$ time ./print3.py rndtabs > /dev/null
real 0m0.634s
user 0m0.535s
sys 0m0.044s
You are not logged in, either login or create an account to post comments
posted by wongcorgi at 2:42 PM on May 9