![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do you parse 1 line at a time of file1 ie. line(n) each line into new file | web_developer | UNIX for Advanced & Expert Users | 4 | 06-28-2009 12:07 PM |
| shell script to read a line in gps receiver log file and append that line to new file | gudivada213 | Shell Programming and Scripting | 3 | 06-24-2009 06:16 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Cheapest way to get line X from file
So, I have a couple of scripts that go through lots and lots of data-- sometimes thousands of smaller files, sometimes a few very large ones. It's very common that I need a particular line, by line number X. There are lots of ways to do this:
Code:
awk 'NR == X {print ; exit}' file
sed -n 'Xp' file
head -n X file | tail -n 1
Code:
awk sed head/tail real 0m1.258s real 0m22.469s real 0m1.011s user 0m1.010s user 0m22.170s user 0m0.550s sys 0m0.250s sys 0m0.280s sys 0m0.730s |
|
|||||
|
try these from sed1liners:
Code:
# print line number 52 sed -n '52p' # method 1 sed '52!d' # method 2 sed '52q;d' # method 3, efficient on large files |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|