Convert text string file to object array without outputting to file first?

I have a log file that is just a text string file which is appended to with Out-File.  If the log file does not exist I pipe headers to it so that I can import the data as CSV.  For example:
DATA.LOG
DATE,TIME,RESPONSE_TIME
05-28-2014, 14:47, 132
05-28-2014, 14:50, 94
05-28-2014, 14:53, 72
I'm using Microsoft Chart Controls to graph the data; it takes it in via CSV format.  If I'm going to chart all the entries in DATA.LOG I can simply IMPORT-CSV DATA.LOG.  But I only want to graph the 20 most recent entries.
Perhaps there is a better way to do this, but to maintain the header and get the 20 most recent entries I'm using select.
$DATA+=Get-Content .\data.log | select -first 1
$DATA+=Get-Content .\data.log | select -last 20
The problem is $DATA is of type system string so I can't use it directly with Chart Controls; I need to get it in CSV format first.  I can Out-File $DATA and then use IMPORT-CSV.  But I'd prefer to not have to use
the temporary file.  Any suggestions on how I can accomplish this objective? 

Import-CSV creates an object with the 'header' becoming the named values in the array.  The code I posted does the same thing as your 4 lines of code in one line of code:
Much more quickly:
PS C:\temp> (1..1000 | measure-command {import-csv .\data.log | select -last 2}).totalseconds
0.4792951
PS C:\temp> (1..1000 | measure-command {$DATATMP=@();$DATATMP+=Get-Content .\data.log | select -first 1;$DATATMP+=Get-Content .\data.log | select -last 2;ConvertFrom-CSV $DATATMP}).totalseconds
1.6227726
You're more than welcome to use whatever code you want, but if you want to improve your Powershell knowledge you should try to understand the object model around which Powershell is built, it is powerful and efficient.
I hope this post has helped!

Similar Messages

  • How to convert imaq image to a 2D array without vision development module

    Hi,
    I'm looking for a way to convert an Imaq image into a regular picture (2D array) without using "Vision development module", nor saving it to a file (I need a refresh rate of about One frame per second).
    any ideas?
    thanks,
    Gilad.

    Greetings, 
    If instead of attempting to acquire the image as the raw data as per the last example, are you looking for something then like the IMAQ Image to Array? I made some research and initially I believed this VI was part of the Development Module, but I was thinking of the Array to Image VI, which is why I did not bring it up earlier.
    Finally, how exactly will you then be manipulating that array? Or will you simply be interested in displaying it? 
    Cordially;
    Simon P.
    National Instruments
    Applications Engineer

  • Converting a String to an Object

    Is there some way of converting a String (from a textfield) to an Object? What I want is something similar to the functionality offerred by a JTable. This is because I want the user to be able to input a value of any type to the textfield (e.g. String, int, boolean, etc) and get its object representation ...
    Would a simple cast do ?
    David

    dattard,
    A string is an object, when someone enters something into a JTextField, REGARDLESS of what it is (int, double, string, etc) it is stored in the string text in that text field (JTextField.getText()).
    So if someone enters in "123", its the STRING 123, not the number one hundred and twenty three... to GET the number 123, you'll need to do something like:
    int value = Integer.parseInt( myTextField.getText() );
    to have the string parsed for the value, if you want a double, same idea:
    double value = Double.parseDouble( myTextField.getText() );
    NOTE: The number wrapper classes (Integer, Double, Float, etc.) contain "parseXXXX" methods that allow you to parse a corresponding numeric value out of a String object.
    Also, when a user enters ANYTHING into a text input field of any type, its ALWAYS a String, if you want a different version of what they entered, its up to you to parse it and decide what it was.

  • Converting a string to Class object and calling its method

    I have recently moved to Java and I need help on this specific issue given below.
    I have to do this :
    ValModule1 val1 = new ValModule1();
    ValModule2 val2 = new ValModule2();
    if(val1.checkModule(xmlDocument)){
    $i++;
    There are many ValModule* classes and they all have the method called checkModule in them. I need to instantiate each class and run the checkMethod which returns true or false. My problem is that I am trying to get the name of the module (if it is ValModule1 or 2 or 3) from the user. What I get from the user is the name of the class for which I should call checkModule method on.
    how can I convert this string validationname given by the user and instantiate that class and call the method?
    I have tried this:
    String str="c:/xpathtest/src/Plugin_Config.xml";
    File xmlDocument = new File(str);
    String cls = "ValModule1"; // assuming this is what the user gave me
    Class t = Class.forName("ValModule1");
    Object o = t.newInstance();
    After that if I try
    if(o.checkModule(xmlDocument)){
    $i++;
    It gives me an error saying that it is not an existing method
    cannot resolve symbol
    [javac] symbol : method checkModule (java.io.File)
    [javac] location: class java.lang.Object
    [javac] if(o.checkModule(xmlDocument)){
    [javac] ^
    [javac] 1 error
    Can you please let me know where I am screwing up :-) ? If you need me to put both the programs I can do that too. Thanks in Anticipation

    I have recently moved to Java and I need help on this
    specific issue given below.
    I have to do this :
    ValModule1 val1 = new ValModule1();
    ValModule2 val2 = new ValModule2();
    if(val1.checkModule(xmlDocument)){
    $i++;
    There are many ValModule* classes and they all have
    the method called checkModule in them. I need to
    instantiate each class and run the checkMethod which
    returns true or false. My problem is that I am trying
    to get the name of the module (if it is ValModule1 or
    2 or 3) from the user. What I get from the user is
    the name of the class for which I should call
    checkModule method on.
    how can I convert this string validationname given by
    the user and instantiate that class and call the
    method?
    Define an interface containing the method all your classes have in common, cast the Object reference returned by newInstance to that interface, then you can call that method.
    Good Luck
    Lee

  • How to convert a string into an objects name?

    Hi
    I have the following problem;
    I have a string
    String a = "e1"
    and a method
    call(Event e1) that calls the "Event" class with object the name of the string a.
    How can I convert the strings name into an object so as to use it in the "call" method?
    Any ideas?
    Thanks in advance

    I don't know if this helps you, but you can do things like this.
    String a = "com.example.SomeEvent";
    //Instantiate com.example.SomeEvent
    Object o = Class.forName(a).newInstance();SomeEvent must have a non-argument constructor for this to work.
    Class that will be instantiated depens on runtime value of String a, and can be different across different executions of the program.

  • Converting text String to XML file data

    need some guidance. I have to create a XML file of a huge Text File.
    I am parsing the text file according to relevance and passing a set of data each element and attribute seperated by "_".
    I need to create to Xml file out this. It has to be current process as I need to keep on adding new elements and attributes.
    e.g.
    Passing this string
    String temp("Name_Age_Birthdate_Birthplace_Place_teleNumber");
    Need to add this to XML of format
    <Directory>
    <Person>
    <Name>
    <Age>
    <Birthdate>.....
    </Person>
    <Person>
    </Person>
    </Directory>
    The problem not all attributes may be present at some time..
    e.g.
    the person's age may be absent some times.. during that time the xml file should look like <Age/>
    I will need to keep on updating Person list concurrently after the file has been created..
    Need Urgent guidance.. I am still New to java
    A guidance code or link is awaited..
    Thanks.. a Lot

    Do you need to stick to the XML support that comes with Java 1.4 or can you use Third-Party stuff? I'm asking, 'cause I think JDOM is much easier to use for a newbie than the build-in XML API ... and it comes with a VERY easy to use class XMLOutputter that creates XML files!
    Take a look at JDOM:
    http://www.jdom.org/

  • How can I convert a string to an object or class

    I would like to read a file representing a class, and convert it to an object or a class (object preferred). Other postings suggest using javax.tools.JavaCompiler to convert from a string but then say that this is not always available (posting on 1 Jan 09). If this is still not universally available is there another way to do this? If this is not available, are there any examples of how it should be done?
    My understanding from what I've read is to read the file into a String then compile the String using javax.tools.JavaCompiler, which is an Interface.
    thanks

    skidmarks wrote:
    What i would like to do is to take a Java file representing a class and compile it at runtime. However, the comment about a JDK being available at runtime makes this unattractive.So, you want to compile .java files, but you don't want to have to use a compiler?
    The next guess would to be to create a .jar file and reference it at runtime. Here's the scenario:Eh? How is that even remotely equivalent?
    1. People using the 'system' will have a varied knowledge of Java.
    2. My hope was to require that anyone using the program would only need to create a Java Class file,You mean a Java source file. You have said that YOU want to create the .class file. If they are creating the .class file, then all you need to do is load it with a ClassLoader and start using it.
    You might try clarifying your requirements a bit.
    In either case, the Class Files would look like:
    public class Name {
    int field1;
    float field2;
    } With all the field types being simple Java Primitives.What is the point of this? What are you ultimately trying to accomplish, that can be served by user-defined groups of primitives, with no complex object graphs and no user-defined methods?
    Depending on what you're really getting at, using scripting features via beanshell, groovy, or javascript might be an approach to consider, or using Scala to produce a domain-specific language (although I suspect that last may be overkill, and beyond your current skill level).
    If this is so, is there any way to create a .jar file at runtime? Do I have to exec("jar") or is there another way.A .jar file is just a .zip file with a manifest. Look at the java.util.jar package. But note that creating a .jar file has nothing to do with the rest of what you're asking about.

  • How to convert a string to date object?

    I have a string user input for date.
    I want to convert it to Date object to insert it in database.
    How to do it?

    Check the java.text.SimpleDateFormat class. You can use it for parsing dates. API contains good description how to build the format pattern.
    HTH
    Mike

  • How to convert text values acceses from jsp page into an xml file?

    /* this is the jsp page which i want to convert it into an xml file
    please help me , i thank in advance*/
    <html>
    <head>
    <title> xml test</title>
    </head>
    <body>
    <form action="testxml2.jsp" method = post>
    <ul>
    <li>
    <ul>NAME:
    <br>
    <li>First Name:<INPUT NAME="firstName" TYPE=text SIZE=20><br>
    <li>Middle Name:<INPUT NAME="middlename" TYPE=text SIZE=20><br>
    <li>Last Name:<INPUT NAME="lastname" TYPE=text SIZE=20><br>
    <li>t Name:<INPUT NAME="tname" TYPE=text SIZE=20><br>
    </ul>
    <br>
    <ul>Role:</b><p><input type="radio" name="role" value="buyer">Buyer<p>
              <input type="radio" name="role" value="seller">Seller<p>
              <input type="radio" name="role" value="thirdparty">Third Party<p>
    </ul>
    <ul>
    Qualification:<br>
    <li>Highest Degree:<INPUT NAME="degree" TYPE=text SIZE=20><br>
    <li>Percentage: <INPUT NAME="percentage" TYPE=text SIZE=20><br>
    </ul>
    <ul> Adress:
    <li> streetName:<INPUT NAME="street" TYPE=text SIZE=20><br>
    <li>cityName:<INPUT NAME="city" TYPE=text SIZE=20><br>
    <li>StateName:<INPUT NAME="state" TYPE=text SIZE=20><br>
    </ul>
    </ul>
    <b>
    <INPUT TYPE=SUBMIT VALUE="ENTER" >
    </body>
    </html>

    hi there,
    In the MCV there is a part about struts, this is a descent way to do this.
    how to do it:
    create an actionform containing all the properties of the page.
    then when you submit your form use an method in the actionforms (that you have written) that makes sets your data in a xml file.
    this works very quickely and i use it in production...
    you can choose if you want the xml to generaded hard coded or via a parser.
    greetings

  • Converting a string to an integer array

    This is kind of a newbie question, but:
    If I have a string which looks like this: "12,54,253,64"
    what is the most effective/elegant/best/etc. way to convert it into an integer array (of course not including the ","s :-)
    Any suggestions are greatly appreciated.

    Thanks, I'll do that. I was looking at StringTokenizer and other things, but it seems they are not implemented in j2me?

  • Convert text to hyperlink within object

    Hi,
    How can I convert part of the text within a text caption to a hyperlink? I do not want the whole text caption to be a Flash hotspot though...
    Thanks for your time

    Hi again
    I'm thinking you could achieve this as follows.
    You could insert a Click Box that you would use to pause the project. The trick would be to time it so it pauses at the right time. You would then configure it as Hidden by clicking the Options tab and clearing the Visible check box. (If it isn't visible, it won't pause).
    Now you configure your Click Box for Multiple actions. The first action would be to open the URL in a New window. The second action would be to show the hidden Click Box you inserted to pause the project.
    Hopefully this helps... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Initialize object array without specifying dimention

    Hi,
    Can anybody help me in suggesting a solution for this:
    I have a class called Test. I can create instance array and initialize for class Test using
    Test test[] = {new Test(), new Test()};
    or
    Test test[] = new Test[100];
    statement.
    How can I give infinite initialization for Test
    Thank you
    Regards
    Anoop

    Anoop.Retna wrote:
    Hi,
    Can anybody help me in suggesting a solution for this:
    I have a class called Test. I can create instance array and initialize for class Test using
    Test test[] = {new Test(), new Test()};
    or
    Test test[] = new Test[100];
    statement.
    How can I give infinite initialization for TestYou can't. There's no such thing.
    If you want a container that can expand to accomodate a variable number of items you can use a List.
    %

  • Load CF varibales into javascript array without outputing to source code

    I have a javascript array for dynamic dropdowns - Automobile, makes,models, etc.
    The javascript arrays are populated by by cf queries
    Everythign works and functions fine - but it also loads the entire array (hundreds of lines of code) into the browser source code.
    I would like to have the javascript arrays hidden from the browser source code by calling it:
    <script language="JavaScript" type='text/javascript' src='../js/super.js'></script>
    But when I code like this, the js file 'super.js' does not run the cf variables.
    The only way I can get it to function right now is to save a cf file called 'super.cfm' and have it run the cf query, then list the javascript code under the query on this cf template.
    THis works - but again, it causes the entire javascript code to be visible to the browser source code...
    any ideas? - I am on cf 7
    thanks in advance

    thanks for your idea
    I ended up rethinking the whole process and realized that I only update my vehicle make/model list about once a week
    So what I ended up doing was creating the the dynamic javascript arrays through cf - and rendered them in a browser, then took the browser source code (the fully rendered javascript arrays) and saved them as a static js file
    My website uses this js file on every page, so I no longer need to call queries on every single page to populate the javascript arrays - they are already built and I am guessing cached by the browser  (browsers cache js files right?)
    SO this runs more efficiently.
    The only draw back is that when I add a new vehicle to the list in my database, I will need to manually do the same process of rendering the new js code, then cutting and pasting it into my static js file that gets called by all pages.
    So it loses the realtime updates - but this only happened once a week anyway - and it only takes me five minutes to create the new file.
    We'll see if I get sick of manually creating a new js file each week - probably, but this seems better than making the server re-render the code on each page.
    Does this make sense? - would this be less overhead on the server than implimenting your concept?
    thanks.

  • Find most repeated name in an array of text String

    Can somebody figure out this problem?
    I have an array of text String, each element in array is simply text String which represents name. Assume the length of array is unknown and names can be repeated once or several times
    The problem is to find out repeated name most
    For example, if giving an array below:
    String[] names = {"Watson", "Tom", "Waton", "Tom","Mike", "Watson","Mike"};we know that Watson will be repeated name most. If we do not know array in advance, how I can find most rrepeated name programmatically using Java?
    thanks

    * NameFinder.java
    * Created on April 12, 2005, 5:40 PM
    package javacore.basics;
    * @author
    public class NameFinder {
        private String[] names=null;
        /** Creates a new instance of NameFinder */
        public NameFinder (String[] names){
            this.names = names;
        public String repeatedNameMost(){
            String nameReturn ="Repeated name not found!";
            int count = 0;
            String tempstring="";
            int tempcount = 0;
            for(int i = 0; i<names.length; i++)
              for(int j=1; j<names.length; j++)
                  if(names.equals(names[j])){ 
    tempstring=names[i];
    tempcount++;
    if(tempcount>count && tempcount>1){
    count = tempcount;
    nameReturn = tempstring;
    return nameReturn;
    public static void main(String[] args){
    String[] names = {"Watson", "Tom", "Watson", "Tom", "Watson", "Mike",
    "Isabel","Zhen","Tom","Isabel","Watson","Watson","Tom","Mike"};
    NameFinder nameFinder = new NameFinder(names);
    System.out.println(nameFinder.repeatedNameMost());
    }// End of NameFinder class
    I have tried to run this code
    However, it doesnot give me what I want
    The output is "Milke" not "Watson" when running the code
    I got some good idea from you
    thanks

  • Converting String to an Object of a class

    Hi all,
    I want to convert a string to an object of a class.
    Please see my below code:
    MyClass rahul = null;
    String data = "DATA";
    rahul = (MyClass) data;
    I am getting the error: Invalid cast from java.lang.String to MyClass
    Please help me as its urgent

    There is no magical String deserialization in java. If your class can convert it's state to a string, then you will need to write the reverse parsing code, presumably using either a constructor which takes a string, or a static method similar to how numbers are handled, like:
    MyClass c = MyClass.valueOf(data);Obviously, in either case you will need to write the code to do this.

Maybe you are looking for

  • How to get rid of thumbnails in conversations in Lync 2013

    After the last update Lync 2013 shows thumbnails next to every IM in the conversation window. Is there a way to get rid of these? I couldn't find anything in the options. It takes up a lot of space and is completely useless for me, as admin has disab

  • Custom 'Save As' file name for cfdocument

    I have a page that generates a PDF (genPDF.cfm). When the user attempts to save it, it saves as genPDF.pdf. Is there any way that when they go to save it, I can dynamically name the document? I am using Blue Dragon 7 here so any cool CF8 additional t

  • Safari iPhone can't play QT movies from certain web pages

    I'm trying to reach QT movies from certain websites and I can't seem to get the streaming video to play in Safari on my iPhone. When I click on the link, it opens a new page. I briefly get a Quicktime logo, then I get a "cannot play" icon (triangle w

  • How to embedd java in bpel?

    I have taken 2 variables in xsd and created a small java program in the same soa project. i want to embed java code in to BPEL and use the variables which i have created in XSD through getVariableData and after calculations the result should go back

  • Is it possible to dynamically create a user variable at runtime from within a Widget?

    I'm trying to develop a custom Interactive Widget. This widget will allow the user to take multiple attempts, and needs to store information about previously completed attempts so they can (hopefully) see their improvements over time. I'm trying to f