Text File Manipulation in Windows using GNU Utilities – head, tail, split

IT

Text File Manipulation in Windows using GNU Utilities – head, tail, split

Oftentimes I find myself needing to work with large text files, and opening up huge files just chokes out even the best text editors. Most of the time, I only need a sampling of the file to get a picture of what is happening, and these are my go-to utilities.

I’m a big fan of Linux and GNU Utilities, but living practically, I use Windows as my primary workstation. One of my first installs on a new build is the GnuWin32 package available at http://gnuwin32.sourceforge.net/ The library is fairly small & lean, and doesn’t require complex environments.

Three useful utilities in the coreutils package – head, tail, and split.

Simply for head and tail:

head -n 50 input.txt

Optionally send the output to a new file:

head -n 50 input.txt > 50lines.txt

tail works the same way, and n specifies to grab the first or last n lines. The default value for n is 10.

split is a little more complicated, here’s the usage:

Usage: split [OPTION] [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
PREFIX is 'x'.  With no INPUT, or when INPUT is -, read standard input.

  -b, --bytes=SIZE        put SIZE bytes per output file
  -C, --line-bytes=SIZE   put at most SIZE bytes of lines per output file
  -l, --lines=NUMBER      put NUMBER lines per output file
  -NUMBER                 same as -l NUMBER
      --verbose           print a diagnostic to standard error just
                            before each output file is opened
      --help              display this help and exit
      --version           output version information and exit

SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.

Report bugs to .

My task for split was to take a large file, and break it up into files no larger than 8MB each. The command used:

split -C8m input.txt split

That results in files no larger than 8MB, prefixed with split, and the best part is it keeps lines together.

More About the Author

Daniel Holm

Director of Enterprise Solutions
Quick Q&A: Why We Like Dell-EMC for Just About Everything IT In this edition of “Quick Q&A,” we talk about Dell-EMC with InterWorks Director of Enterprise Solutions Daniel Holm, IT ...
Testing the Beta NVIDIA RTX Audio Driver NVIDIA is always pushing the limit of what their video cards can do. However, they have now started to use the AI abilities they ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072