Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract N lines from file using single windows command

Tags:

Is there a way to extract/copy the fist X number of lines from a file and input them into another file with a single command using the windows command prompt?

I can delete the first X number of lines using:
more +X [file_containing data] > [file_to_export_data_to]

If the head command would work I think I could just do this:
head -X [file_containing data] > [file_to_export_data_to]

But that unfortunately does not work.

It would be great if Windows had a "less" command but again no luck.

I'm a complete novice when it comes to this stuff so I'm sure I'm missing something obvious. I don't want to install anything or use something other than the command prompt.

Thanks

like image 425
user1769292 Avatar asked Jan 13 '15 22:01

user1769292


People also ask

How do I use command prompt to extract?

Press the "Enter" key. - Type "unzip [file_location]\[filename. zip]" into the command prompt, replacing "[file_location]" with the full directory path and "[filename. zip]" with the name of the ZIP file you want to extract.


1 Answers

the simplest one-command solution is to use Powershell Get-Content.

N - number of lines.

From the begining of file:

Get-Content -Head N file.txt 

From the end of file:

Get-Content -Tail N file.txt 
like image 146
Janusz Avatar answered Oct 01 '22 12:10

Janusz