Add data to csv input file

Im using a csv file as my data input for a test. The test data is simply recorded in an array. How do I add this array data back to the original csv file, as an additional column, once the stop button is clicked?
Solved!
Go to Solution.

Actually, you do not have to read the whole file at once, although that does make the programming easier.  You can read and write data in chunks to keep memory usage down and file write efficiency up (65,000 byte file chunks give best read and write performance on Windows systems).  You will end up with a steadily increasing memory buffer as you read a chunk from disk, add to it, then write what you can to disk before reading another chunk.  At the end, you will have a buffer the same size as your added data that you can then stream to disk at the end to finish the file.  The algorithm would go something like this:
Read N bytes from disk
Modify as needed by adding data at the end of each row.  Your data is now of size N + M
Write N bytes to disk, keeping the remaining M in a memory buffer
Read the next N bytes from disk
Modify and append to the current M bytes from the previous iteration.
Write N bytes to disk, keeping the remaining in a memory buffer
Repeat steps  4 - 6 until the entire file has been read.  You now have a buffer of left over data.
Stream leftover data to end of file in 65,000 byte chunks.
In theory, this would give better performance, if done well, since you do not need to convert the entire file to numbers, then back again, but only need to convert the numbers going into the file into text.  In practice, if you are not very careful, all the appending and reshaping of strings and arrays can cause memory issues if you don't reuse and manage the buffers intelligently, causing slowdowns.  This can be made disk speed limited, if done correctly.
This account is no longer active. Contact ShadesOfGray for current posts and information.

Similar Messages

  • Add date to new text file name and generic text in body

    Okay, I hope this is the right forum. To help manage and keep track of incoming assets/files and I created an Automator workflow with the following: "Get Selected Finder Items → Get Folder Contents → New Text File (w/Show this action when the workflow runs so I can give a unique name).
    This creates a text file with the folder contents listed in the body.
    I would like to know if I can do two things:
    1. Automatically add a date/time stamp to the Save as field so it will automatically have a unique file name?
    2. I also want to add text before the listed contents within the text file. (e.g.: Let's say the folder contents are Volumes/Mac HD/Generic_movie.mov. I want the final text to read:
    "The following file has been moved to the local volume at: Volumes/Mac HD/Generic_movie.mov"
    Is there a way to accomplish either one or both of these with Automator or AppleScripts?
    Thanks.

    I would like to know if I can do two things...
    This might address your first concern:
    *1) Get Selected Finder Items*
    *2) Get Folder Contents*
    *3) New Text File* -- select a destination folder and check *Show Action When Run*
    *4) Rename Finder Items:*
    Choose *Add Date or Time* from the popup
    Date/Time: select Created, Modified, or Current - Format: *Month Day Year*
    Where: *After name* - Separator: *Forward Slash*
    Separator: Space - check *Use Leading Zeros* (optional)
    *5) Rename Finder Items:*
    Choose *Add Text* from the popup
    Add: *" at"* -- put a leading space before "at" (without the quotes), and select *after name*.
    *6) Rename Finder Items:*
    Choose *Add Date or Time*
    Date/Time: Current - Format: *Hour Minute Second*
    Where: *After name* - Separator: Dash
    Separator: Space - check *Use Leading Zeros* (strongly recommended)
    +--- End of Workflow ---+
    Save the workflow as an application and use it as a droplet. Drop a desired folder onto the saved applet and enter a name when the dialog appears. The new text file, which will be found in the destination folder, should be appended with a date and time stamp, e.g., *"My Folder List 7/8/2010 at 23-54-09"*
    Tested using Mac OS 10.4.11 and Automator v. 1.0.5
    Good luck; hope this helps.

  • How do I add data to an existing file, without having to create a new one?

    Hi,
    I made a servlet which is supposed to write the word "new" in a file everytime the server creates an instance:
    File chatInfos = new File("LOCATION_OF_THE_FILE/infos.dat");
       if(chatInfos.exists()) {
        try {
        FileOutputStream fos = new FileOutputStream(chatInfos);
        ObjectOutputStream os = new ObjectOutputStream(fos);
        os.writeObject("new");
        os.close();
        fos.close();
        } catch(IOException e){};
       }But it doesnt work. It seems like that every time the old file is destroyed and a new one is created. But I dont want that. I simply want to add a new object to the file.
    thanx

    http://java.sun.com/j2se/1.4.1/docs/api/java/io/FileOutputStream.html#FileOutputStream(java.io.File, boolean)
    Kind regards,
    Levi

  • Need to add date/time stamp to file name without time change creating new files

    We have setup our application to save data once a trigger event occurs. We also need the date/time stamp as part of the file name. We used Format Date/Time String and concatenated it into the file name. It all works good, but as the time changes (seconds, minutes, etc.) it causes the Write to File to create a new file with the new filename. Is there a way to create the file and save/latch/buffer the time in the file name so that it doesn't create a new file for every second?
    I've attached a shot of the relevant part of our VI. It's all in a big while loop. The data save is in a case/switch so that when it is triggered it starts saving. (The for loop is to split the data up
    into 4 different files). Like I said, it all works except new files are created every second as the time changes instead of just putting it all in one file with the initial time in the file name.
    Attachments:
    TimeInFileNameQuestion.jpg ‏46 KB

    I need a loop in order to use a shift register. I cannot stop the outer while loop (because it would stop the hardware from collecting data), and I cannot add loops inside which bogs down the processor to where the app stops. I've attached a simpler version of my VI which illustrates the problem. While the button is pressed (the trigger) it should save the data (in this case just cycle numbers) into one file with the initial date/time. But, you can see that it creates 1 file/second. I tried using shift registers, but without adding extra loops I can't see how to do it. Thanks
    Attachments:
    FileNameTest.vi ‏29 KB

  • Add data to end of file

    I'm using a file created using the following:
    RandomAccessFile raf = new RandomAccessFile("MyFile.dat");I'm adding data using the writeBytes command.
    raf.seek(filePtr);
    raf.writeBytes(data + "\n");
    filePtr = (int) raf.getFilePointer();
    ......I need to append data to the end of file when it matches a condition. Is there any way I can find the position of End of the File. In C++ we can use seekp(0, ios::end) to find end of a file. Can we do something like that in Java? Please help me.

    Hi,
    What you say makes sense... but I'm working on my thesis in which I need to implement a grid file, hence the doubt.

  • How to add data in xml file

    Hi ALL
    I want to add new fields on seeded EBS page to store their values in hr_api_transaction table whoch contain information of other fields on that page which are seeded
    but that table has one column which stores xml file and that xml file has all information about that page's fields
    how can I store my custom fields values in that xml file ?

    Hi,
    As Andy said,  add data to an xml file is overwriting, if you mean append data to xml file, please look this article:
    http://codesamplez.com/programming/linq-to-xml-tutorial, Since this issue is more related to ASP.net, you could also ask this issue in asp.net forum:
    http://forums.asp.net/
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Loading into CSV format file

    I'm trying to load data into csv format file, by adding "," at the "Text Delimiter" at the "Files" tab. However, it adds several commas as:
    ,aaaaaa , ,aaaaaaaa , ,aa,
    ,bbbbbb , ,bbbbbbbb , ,bb,
    ,cccccc , ,cccccccc , ,cc,
    Can anyone confirm if it's right way to load into csv file?

    There is too many commas!
    You should not use a comma in your text delimiter but a quote' or double quote"
    and put a comma in the field separator to have something like
    "aaa","aaaa","aa"

  • Adding data in an XML file

    how to add  data in xml file from textbox in c# without overwriting???

    Hi,
    As Andy said,  add data to an xml file is overwriting, if you mean append data to xml file, please look this article:
    http://codesamplez.com/programming/linq-to-xml-tutorial, Since this issue is more related to ASP.net, you could also ask this issue in asp.net forum:
    http://forums.asp.net/
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How do you read data from a text file into a JTextArea?

    I'm working on a blogging program and I need to add data from a text file named messages.txt into a JTextArea named messages. How do I go about doing this?

    Student_Coder wrote:
    1) Read the file messages.txt into a String
    2) Initialize messages with the String as the textSwing text components are designed to use Unix-style linefeeds (\n) as line separators. If the text file happens to use a different style, like DOS's carriage-return+linefeed (\r\n), it needs to be converted. The read() method does that, and it saves the info about the line separator style in the Document so the write() method can re-convert it.
    lethalwire wrote:
    They have 2 different ways of importing documents in this link:
    http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
    Neither of those methods applies to JTextAreas.

  • Adding data from a text file into a JTextArea

    I'm working on a blogging program and I need to add data from a text file named messages.txt into a JTextArea named messages. How do I go about doing this?

    then you need to be more specific in what you need help with because those are two commonly used options for reading data in from a file. what have you tried? where is your code failing? what kind of errors are you getting? of course it looks like others in the forum have already reprimanded you for failing to post properly.
    i have used both FileReader and the nio package for cfg and ini files which are both just txt files as well as massive data files. so tell me how they dont help you?

  • Help with delimiters, input files, and mapping scheme

    A node has a name, processing power, neighbors, and cost to each neighbor
    I'm reading this data from an input file:
    node power neighbors cost to each neigbor
    A: 1.1 B, C 4, 5
    B: 2.3 A 4
    C: 3.1 A 2
    I use StringTokenizer to capture each group.
    I place each group in an ArrayList.
    The problem is mapping B,C to their cost from A, etc.
    I have a Node class
    I have a Link class
    I just don't what method to retrieve the neighbors and cost to it's src

    Ok, I'm trying to create a graph
    I'm using an arraylist for the name of nodes, an arraylist for the processing power, and an arraylist for the neighbors and cost. I just don't know how to map the neighbors and cost to name of the nodes.
    Help me!!!!!!!!!
    I created a Node class with a name and processing power, and neighbors
    I create a Neighbor class with a name and cost!
    The data is coming from an input file..............
    I uses and array to allow the user to create as many nodes and neighbors, but I need to get the information on each node. HEEEEEEEEEEELP ME

  • Add data to table view from input fields in a page

    Hi
            I am developing a BSP page which will be called from SRM shop transaction. After user enters the line item data, data will be passed back to shop transaction using OCI interface and the page attributes (URL).
       (1) How can I add data from input fields to table view on a page on a button click? I am able to add first line but I could not retain first line data when I try to add the second line.
          I am able to add multiple lines to table view if I use view and controller by adding to the line data to static attribute of the controller. I can’t use the controller and view because I can not set the attribute to Controller automatically.
       (2) Is there a way to pass an attribute (URL) to controller from SPRO? Like we pass an attribute to page automatically (Automatic page attribute).
       (3) How can I call a controller and view and pass the page attribute to the controller on a button click from a page with out controller?
    Thanks
    Sreenivas

    I'm trying to test the merge with the following data in a test.txt file:
    ZZZZZ114923000004
    1234Z400660000001
    ZZZZZ114923000010
    Getting an error:
    SQL> @C:\dataformats\sql\pc12seriesMerge.sql
    Directory created.
    SP2-0552: Bind variable "17" not declared.
    SQL>
    here it the pc12seriesMerge.sql file
    set serveroutput on
    create or replace directory user_dir as 'c:\dataformats\incoming\';
    DECLARE
    v_filename VARCHAR2(100); -- Data filename
    v_file_exists boolean;
    v_file_length number;
    v_block_size number;
    f utl_file.file_type;
    s varchar2(200);
    lineString varchar(200);
    v_account varchar(5);
    v_IDN varchar(6);
    v_quantity varchar(6);
    BEGIN
    v_filename := 'TEST.TXT';
    DBMS_OUTPUT.PUT_LINE(v_filename); --shows filename
    utl_file.fgetattr('USER_DIR', v_filename, v_file_exists, v_file_length ,v_block_size );
    IF v_file_exists THEN
    dbms_output.put_line('File Exists');
    create table ext_table (
    account varchar2(5),
    idn number(6),
    quantity varchar2(6)
    organization external (
    type oracle_loader
    default directory user_dir
    access parameters (
    records delimited by newline
    fields (
    account position(1:5) char(5),
    idn position(6:11) char(6),
    quantity position(12:17) char(6)
    location ('test.txt')
    reject limit unlimited;
    MERGE INTO id_req_stg t
    USING (
    SELECT account,
    idn,
    decode(quantity, '-', 0, to_number(quantity)) as quantity
    FROM ext_table
    ) v
    ON ( t.account = v.account AND t.idn = v.idn )
    WHEN MATCHED THEN
    UPDATE SET t.quantity = v.quantity
    DELETE WHERE t.quantity = 0
    WHEN NOT MATCHED THEN
    INSERT (account, idn, quantity)
    VALUES (v.account, v.idn, v.quantity);
    ELSE
    dbms_output.put_line('File Does Not Exist');
    END IF; -- file exists
    EXCEPTION
    WHEN UTL_FILE.ACCESS_DENIED THEN
    DBMS_OUTPUT.PUT_LINE('No Access!!!');
    WHEN UTL_FILE.INVALID_PATH THEN
    DBMS_OUTPUT.PUT_LINE('PATH DOES NOT EXIST');
    WHEN others THEN
    DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
    END;
    /

  • Error while running bulk load utility for account data with CSV file

    Hi All,
    I'm trying to run the bulk load utility for account data using CSV but i'm getting following error...
    ERROR ==> The number of CSV files provided as input does not match with the number of account tables.
    Thanks in advance........

    Please check your child table.
    http://docs.oracle.com/cd/E28389_01/doc.1111/e14309/bulkload.htm#CHDCGGDA
    -kuldeep

  • Error while load the data from CSV with CTL file..?

    Hi TOM,
    When i try to load data from CSV file to this table,
    CTL File content:
    load data
    into table XXXX append
         Y_aca position char (3),
         x_date position date 'yyyy/mm/dd'
    NULLIF (x_date = ' '),
    X_aca position (* + 3) char (6)
    "case when :Y_aca = 'ABCDDD' and :XM_dt is null then
    decode(:X_aca,'AB','BA','CD',
    'DC','EF','FE','GH','HG',:X_aca)
    else :X_aca
    end as X_aca",
    Z_cdd position char (2),
         XM_dt position date 'yyyy/mm/dd'
    NULLIF XM_dt = ' ',
    When I try the above CTL file; geting the following error..
    SQL*Loader-281: Warning: ROWS parameter ignored in parallel mode.
    SQL*Loader-951: Error calling once/load initialization
    ORA-02373: Error parsing insert statement for table "XYZ"."XXXX".
    ORA-00917: missing comma

    Possible Solutions
    Make sure that the data source is valid.
    Is a member from each dimension specified correctly in the data source or rules file?
    Is the numeric data field at the end of the record? If not, move the numeric data field in the data source or move the numeric data field in the rules file.
    Are all members that might contain numbers (such as "100") enclosed in quotation marks in the data source?
    If you are using a header, is the header set up correctly? Remember that you can add missing dimension names to the header.
    Does the data source contain extra spaces or tabs?
    Has the updated outline been saved?

  • File/Hadoop CSV input : Discovery of file fails

    Hello ,
    I'm trying to make the project as described in -
    "Hands-on Tutorial: Building a Simple SAP Sybase ESP Project" for SAP Sybase ESP version 5.1 SP04.
    I create a project where I add an input adapter of type - File/Hadoop CSV input.
    Then in edit properties I enter the directory and the file name . In advanced tab I also set Has Header = TRUE.
    Then  I click on Schema Discovery and this raises error - "Failed to parse discovery file : parse of file failed ".
    I've imported the sample "towermon "project from SCN and this shows the same error !
    I've done this before on SP02 and it used to work . Of course the File/Hadoop CSV input adapter did not exist in that release.
    Can't quiet figure out what I'm doing wrong . Is this a bug in the software ?Any ideas how to fix this ?
    Best regards,
    Saty

    Hello,
    Two things to check:
    1)  I don't know which file you are using from the "towermon" project.  One of the CSV files (input-streams.csv) prepends the stream name and opcode:
    isSensorStream,i,2011-06-30T17:00:00.000,32.835,-114.188,Tower,Yuma T70,1,104,0
    The other CSV files do not.  So you will have to toggle the "csvExpectStreamNameOpcode" parameter to true/false (the default is true).
    2) There is a bug in the adapter discovery mechanism where it will return the error Failed to parse discovery file : parse of file failed ":
       749503 - Schema discovery does not work for toolkit adapters when unnecessary properties are listed on the adapter.
    So for example, in text authoring mode, if you have this:
    ATTACH INPUT ADAPTER File_Hadoop_CSV_Input1 TYPE toolkit_file_csv_input PROPERTIES
    csvExpectStreamNameOpcode = TRUE ,
    dir = 'c:/temp' ,
    file = 'input-streams.csv' ,
    dynamicMode = '' ,
    removeAfterProcess = FALSE ,
    csvDelimiter = '' ,
    csvDateFormat = '' ,
    csvTimestampFormat = '' ,
    csvHasHeader = FALSE ,
    pollingPeriod = 0 ,
    scanDepth = 0 ;
    You have to delete the unnecessary properties:
    ATTACH INPUT ADAPTER File_Hadoop_CSV_Input1 TYPE toolkit_file_csv_input PROPERTIES
    csvExpectStreamNameOpcode = TRUE ,
    dir = 'c:/temp' ,
    file = 'input-streams.csv' ;
    Then switch back to visual authoring mode and try discovery again.
    Hope this helps.
    Thanks,
      Neal

Maybe you are looking for