How to delete lines after n-th line

I have very basic knowledge about powershell, i still learning. so please don’t get mad if i asking silly question

here is the job i am trying to achieve:

i have multiple text files

c:\text\abc.txt

c:\text\cdb.txt

 

inside text there is content lets say

line 1 asdb

line 2 asdas

line 3 sfsdsfd

line 4 sgsf

line 5 sgfsdf

line 6 sfsf

…line 100 sfsdf

 

i want to remove all line after line 5 and save the text file. will it be possible to do it using powershell?

 

 

yes it is. pick the first 5 lines with select -first 5 and then output that to a file.

thank you problem solved :slight_smile: