Skip to content

Instantly share code, notes, and snippets.

@dahjelle
Created April 6, 2017 16:01
Show Gist options
  • Save dahjelle/274530c9da934bc833964421ff0269b5 to your computer and use it in GitHub Desktop.
Save dahjelle/274530c9da934bc833964421ff0269b5 to your computer and use it in GitHub Desktop.
Tips For Processing Large Files

Tips for Processing Large Files

Extract the First 100 Lines

head -n 100 filename.txt > smallfile.txt

Extract the Last 100 Lines

tail -n 100 filename.txt > smallfile.txt

Extract Lines 100 to 200 (even of multi-GB files!)

sed -n '100,200p;200q' filename.txt > smallfile.txt

Extract the First 100 Lines That Match Text

grep -m 100 'text_to_search' filename.txt > smallfile.txt

Redirect StdOut to Vim

Instead of echo text > smallfile.txt, you can avoid the temporary file and go right to vim with:

echo text | vim -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment