How to delete lines after n-th line

Welcome Forums General PowerShell Q&A How to delete lines after n-th line

Viewing 2 reply threads
  • Author
    Posts
    • #195917
      Participant
      Topics: 2
      Replies: 1
      Points: 8
      Rank: Member

      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?

       

       

    • #195944
      Participant
      Topics: 5
      Replies: 105
      Points: 262
      Helping Hand
      Rank: Contributor

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

    • #195986
      Participant
      Topics: 2
      Replies: 1
      Points: 8
      Rank: Member

      thank you problem solved 🙂

Viewing 2 reply threads
  • You must be logged in to reply to this topic.