No Skipline in Powershell?

Author Message
who10

  • Total Posts : 36
  • Scores: 0
  • Reward points : 0
  • Joined: 4/29/2006
  • Status: offline
No Skipline in Powershell? Tuesday, June 30, 2009 4:24 PM (permalink)
0
So I'm attempting to convert one of my vbscripts to powershell in an attempt to learn. I run into a line where I am using the skipline method in vbscript.  I search for the powershell equivalent and I can't find it... anywhere... Does it exist?  Am I the only scripter on the planet that sees a need for this method when parsing text files? 
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: No Skipline in Powershell? Wednesday, July 01, 2009 2:44 AM (permalink)
    0
    Well if you present the situation where you need to do a skip line then I'm sure we can work out a powershell way to do it. I have to be honest that I can't remember ever having used SkipLine in VBScript.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      who10

      • Total Posts : 36
      • Scores: 0
      • Reward points : 0
      • Joined: 4/29/2006
      • Status: offline
      RE: No Skipline in Powershell? Wednesday, July 01, 2009 3:06 AM (permalink)
      0
      Let's say we are working with a log file that contains some text like
       
      Application log file
      Number of licenses in use
      ===============
      40
       
      This text will be in a log file with hundreds of lines in it and may not be at the same line every time.
      A couple of consistancies  are that "Number of licenses in use" will always exist somewhere in the file and
      "=================" will always be on the line below it.
       
      I am interested in the line below that, which contains the number of licenses in use, "40".
       
      In vbscript, I look for the "Number of licenses in use", then I use skipline to go to the line I am interested in,
      which in this case would be the line which contains the string "40".
       
      I then pass this value to a variable and do what I want with it.
       
      Does this make sense? 
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        RE: No Skipline in Powershell? Wednesday, July 01, 2009 3:20 AM (permalink)
        0
        I understand. There are three ways that I would handle this in either VBScript or Powershell.
         
        First if the file is really really large and I didn't want to read the entire thing into memory, I would use a flag. So as I was reading along and I saw "Number of licenses in use" I would do bGetNumber = True. For every line I would do If bGetNumber and IsNumber(strLine) Then (get the number and bGetNumber = False).
         
        Second if the file is small enough to read into memory, I could use a regex to grab a number that is preceded by "Number of licenses in use" and a line of =s.
         
        Third if I can read the entire file, I just slurp it all up into an array. Then whenever I see "Number of licenses in use" I know that the number I want is arrLines(index + 2).
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          who10

          • Total Posts : 36
          • Scores: 0
          • Reward points : 0
          • Joined: 4/29/2006
          • Status: offline
          RE: No Skipline in Powershell? Wednesday, July 01, 2009 5:28 AM (permalink)
          0
          I appreciate the help.  I'll play around with a couple of those methods.  Maybe I'll learn something new here
           
          #5
            jhicks

            • Total Posts : 2
            • Scores: 0
            • Reward points : 0
            • Joined: 7/2/2009
            • Status: offline
            RE: No Skipline in Powershell? Thursday, July 02, 2009 1:16 AM (permalink)
            0
            Text parsing in PowerShell can be done with the Select-String cmdlet.  If you'd like, post your VBScript and I'll point how to make it more PowerShell-like.
            Jeffery Hicks
            Microsoft PowerShell MVP
            http:/jdhitsolutions.blogspot.com
            follow me: http://www.twitter.com/JeffHicks

             
            #6

              Online Bookmarks Sharing: Share/Bookmark

              Jump to:

              Current active users

              There are 0 members and 1 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2012 ASPPlayground.NET Forum Version 3.9