Search code examples
sublimetext3

Read only nth first lines [sublime text]


I've got some files so big to directly open them in Sublime Text. Is there any way to open only the nth first lines? Something like head in bash? Thanks


Solution

  • If you're on Linux or Mac, or have Cygwin, Git Bash, or similar installed on a Windows machine, check out the split utility, which is part of the coreutils package. It does exactly what it says: it splits input into separate files. It is configurable via command-line options, like every Unix utility. For example, if you wanted to split your input file into separate 10,000-line files starting with notsobigfile and using numeric suffixes ending with .txt, you would run

    split -d -l 10000 --additional-suffix=".txt" reallybigfile.txt notsobigfile 
    

    and it would output files named notsobigfile01.txt, notsobigfile02.txt, etc. If this would generate more than 100 files (00 through 99), just add -a x where x is the number of digits (the default is 2).

    For all the possible options, just read the man page:

    man split
    

    If you only want to output the first part of the file, check out the options for the -n/--number flag.

    To figure out how many lines your input file has, run the word counting utility using the lines option:

    wc -l reallybigfile.txt