![]() Maybe I'll get around to it one of these days. * I keep meaning to post yet another update to that script. You just seek linelength * linecount characters into the file. In the case of the fixed record length file, it's really easy. In the log file example, you could do a binary search for a range of times as my Python script here* does. If, however, the file is sorted (a log file with timestamps, for example) or has fixed length lines, then you can seek into the file based on a byte position. The problem is that for unsorted files with variable length lines any process is going to have to go through the file counting newlines. Starts at the ten millionth line from the end of the file, while your "middle" command would seem to start at the ten millionth from the beginning which would be equivalent to: head -n 10000010 filename | tail 10 The p command "print the current pattern space" and the q command "Immediately quit the sed script without processing any more input." The quotes are from the sed man page.īy the way, your command tail -n 10000000 filename | head 10 In those commands, the option -n causes sed to "suppress automatic printing of pattern space". In this example print 1 to 5 lines: sed '1,5p' / etc /passwd The ‘p’ command is preceded by line rage address 1,5 (separated by a comma). ![]() ![]() You can tell sed to perform prints only on a particular line or lines. The number ‘2’ refers to line number two. You might be able to speed that up a little like this: sed -n '10000000,10000020p 10000021q' filename sed '2p' / etc /passwd The ‘p’ command is preceded by a ‘2’.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |