Hi all,
How can I quickly show Nth line from the huge file(at least more than 15GB)? I used the following script but seems slower.
See 2717298 th line.
head -2717298 data0802.dat | tail -1
Thank you very much
Hi all,
How can I quickly show Nth line from the huge file(at least more than 15GB)? I used the following script but seems slower.
See 2717298 th line.
head -2717298 data0802.dat | tail -1
Thank you very much
You're going to need to read the file until line 2717298 and that will take some time. But try:
sed -n '2717298{p;q;}' datafile
sed 'NUMBERq;d' file
.. where NUMBER is the line number you want displayed
Thank you very much
for large files , use awk
# wc -l file
9812605 file
# time sed -n '2717298{p;q;}' file
2717298 this is a line
real 0m9.412s
user 0m9.313s
sys 0m0.080s
# time sed '2717298q;d' file
2717298 this is a line
real 0m9.595s
user 0m9.329s
sys 0m0.052s
# time awk 'NR==2717298{print;exit}' file
2717298 this is a line
real 0m1.227s
user 0m1.148s
sys 0m0.072s
# time sed -n '2717298{p;q;}' file
2717298 this is a line
real 0m9.616s
user 0m9.429s
sys 0m0.080s
# time sed '2717298q;d' file
2717298 this is a line
real 0m9.105s
user 0m9.005s
sys 0m0.084s
# time awk 'NR==2717298{print;exit}' file
2717298 this is a line
real 0m1.247s
user 0m1.164s
sys 0m0.080s