Need help: UTL_FILE read and write in the text file

Hello, I'm on version 11 GR 2 by using the UTL_FILE function to read a text file and then write the lines where it starts with the word "foo" and put an end to my writing in the text file where the line with the word "ZEN". Now I have several lines that begin with 'foo' and 'ZEN' allow a paragraph, and in this paragraph, there is a line that begins with "DE4.2". Therefore,.
I need to write all of the paragraphs that include the "DE4.2" line in their beginning and end of lines 'foo' and 'ZEN '.

FOR EXAMPLE:

FOO/234E53LLID
IT'S MY SECOND LINE
IT'S MY THIRD LINE
DE4.2 IT OF MY FOURTH LINE
IT'S MY FIFTH LINE
ZEN/DING3434343

FOO/234E53LLID
IT'S MY SECOND LINE
IT'S MY THIRD LINE
IT'S MY FIFTH LINE
ZEN/DING3434343

I'm only interested in writing the first paragraph tha includes line DE4.2 in one of the paragraph of lines not the second ther that does not include the "DE4.2".

Here is my code so far:

CREATE OR REPLACE PROCEDURE my_app2 IS
Utl_file.file_type INFILE;
outfile utl_file.file_type;
buffer VARCHAR2 (30000);
b_paragraph_started BOOLEAN: = FALSE; -flag to indicate which required paragraph is started

BEGIN
-Open a file to read
INFILE: = utl_file.fopen ('TEST_DIR', 'mytst.txt', 'r');
-Opens a file for writing
outfile: = utl_file.fopen ('TEST_DIR', "Out.txt", "w");

-Check the file is open
IF utl_file.is_open (infile)
THEN
-lines in the file in loop
LOOP
BEGIN
UTL_FILE.get_line (infile, buffer);
APPLICATION STARTING POINT-
Buffer IF LIKE 'foo %' THEN
b_paragraph_started: = TRUE;
END IF;
-SEARCH FOR GRADS APPS
IF b_paragraph_started AND buffering LIKE '% 4% ' THEN
UTL_FILE.put_line (outfile, buffer, FALSE);
END IF;
-REQUEST FOR ENDPOINT
Buffer IF LIKE '% ZEN' THEN
b_paragraph_started: = FALSE;
END IF;
UTL_FILE.fflush (outfile);

EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
END LOOP;
END IF;
UTL_FILE.fclose (INFILE);
UTL_FILE.fclose (outfile);
EXCEPTION
WHILE OTHERS THEN
raise_application_error ("-20099, ' UTL_FILE unknown error");
END my_app2;
/

When I run this code I get only one line: DE4.2 it ME LACK THE WHOLE PARAGRAPH

PLEASE ADVISE...

I agree with reservations of Justin on the length of a "paragraph" and the number of users that are running at the same time, so here is a version without the collections.

CREATE or replace PROCEDURE my_app2 IS
   infile utl_file.file_type;
   outfile utl_file.file_type;
   buffer VARCHAR2(30000);
   b_paragraph_started BOOLEAN := FALSE; -- flag to indicate that required paragraph is started
   b_toprint BOOLEAN := FALSE;
   l_para_start pls_integer;  -- start of "paragraph"
BEGIN
   infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r');
   outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w');
   LOOP
      BEGIN
         utl_file.get_line(infile, buffer);
         IF buffer LIKE 'FOO%' THEN
            b_paragraph_started := TRUE;
            l_para_start := UTL_FILE.FGETPOS(infile) - (length(buffer) + 1);
         END IF;
         IF b_paragraph_started and buffer like '%DE4%' THEN
            b_toprint := TRUE;
         END IF;
         If buffer like 'ZEN%' THEN
            IF b_toprint THEN
               UTL_FILE.FSEEK(infile, l_para_start);
               utl_file.get_line(infile, buffer);
               while buffer not like 'ZEN%' loop
                  utl_file.put_line(outfile,buffer, FALSE);
                  utl_file.get_line(infile, buffer);
               end loop;
               utl_file.put_line(outfile,buffer, FALSE);
            end if;
            b_paragraph_started := FALSE;
            b_toprint := false;
            utl_file.fflush(outfile);
         end if;
      EXCEPTION
         WHEN no_data_found THEN
            EXIT;
         END;
   END LOOP;
   utl_file.fclose(infile);
   utl_file.fclose(outfile);
END my_app2;

Test:

SQL> !cat mytst.txt
FOO/234E53LLID
THIS IS MY SECOND LINE
THIS IS MY THIRD LINE
DE4.2 THIS IS MY FOURTH LINE
THIS IS MY FIFTH LINE
ZEN/DING3434343

FOO/234E53LLID
THIS IS MY SECOND LINE
THIS IS MY THIRD LINE
THIS IS MY FIFTH LINE
ZEN/DING3434343

FOO/234E53LLID again
THIS IS MY second SECOND LINE
THIS IS MY second THIRD LINE
DE4.2 THIS IS MY second FOURTH LINE
THIS IS MY second FIFTH LINE
ZEN/DING3434343 again

SQL> exec my_app2;

PL/SQL procedure successfully completed.

SQL> !cat out.txt
FOO/234E53LLID
THIS IS MY SECOND LINE
THIS IS MY THIRD LINE
DE4.2 THIS IS MY FOURTH LINE
THIS IS MY FIFTH LINE
ZEN/DING3434343
FOO/234E53LLID again
THIS IS MY second SECOND LINE
THIS IS MY second THIRD LINE
DE4.2 THIS IS MY second FOURTH LINE
THIS IS MY second FIFTH LINE
ZEN/DING3434343 again

You may need to change the length (buffer) + 1 depending on your platform and if you want a blank line s NLE out paragraphs, add another call to put_line after that outside of the loop in the fi l_toprint block.

John

Tags: Database

Similar Questions

  • Can all help with VI to get data (HEX) serial number and write in the text file

    Hello I am struggling with this problem for 2 months... They get help from different I thought I solved the problem, but of no use yet I stand on zero

    Problem: I need to get data on USB high speed HEXAGON shaped (coming in hexadecimal and be stored in the text file to the hexadecimal format as each hexadecimal value online different I'll also to attach the file)

    Get us ASCII on series or VISA read but when trying to convert to hex as shown in text file making it slower to deal with code, I know that my VI will have to improve more... I'm waiting for suggestions

    Need urgent help...

    Thanks in advance

    Hi Ali Afzal,.

    I think that the attached example can work for you. If not, then try the solution with sending the data to a parallel running the loop and store it there.

    Mike

  • [Help] Need help to remove a string in the text file

    Hi all

    I have a text like this

    REPORT

    Wednesday, June 10, 2015 14:31:56

    **********************************************************************************

    HOST: 10.9.1.185

    TestVM is turned off

    **********************************************************************************

    HOST: 10.9.0.84

    All virtual machines are turned off

    **********************************************************************************

    HOST: 10.9.0.85

    **********************************************************************************

    HOST: 10.9.0.86

    I want to remove the

    **********************************************************************************

    HOST: 10.9.0.85

    **********************************************************************************

    HOST: 10.9.0.86

    because there is no information after the HOST 10.9.0.85 or: 10.9.0.86

    It will reduce the content of the report

    I need a script to delete this text

    Could someone help me?

    Thank you for your help

    What generates the report? It is probably easier to just do not write to the file in the first place...

  • How to catch exceptions and write in the text file

    For all developers,.

    This is the problem,

    I want to print my exception stack trace in a text file.

    This developer can know and analyze on what function is error and what exception for this error...

    Is it possible to do this?

    Thank you...

    Yes, you can write like try (), it returns a string, and you can write that string to the file.

  • TCP Read and Write at the same time

    Hello everyone,

    I have a question about parallelism in TCP connections.

    I know that it is possible to read and write on the same connection ID.

    So, if you ReadTCP and WriteTCP block each other, if you use the same TCP connection ID?

    Or to request more precise if I run two while loops, in parallel, with one end by calling WriteTCP and the other called ReadTCP.

    one of the delay of loops (or block) will be the other if both loops call their VI TCP at the same time right?

    The system is Windows 7 and Labview 2012.

    Kind regards

    Sebastian

    They are perfectly parallel.  Just write in one and read it from the other.  There is no conflict.

    See My TCP articles for more details.

  • Need help to open two images with the same file with different exposures on the screen at the same time in the Photoshop creative cloud (in previous versions we could open two images of the same nef (raw) file and then combine them on the screen with the

    Need help to open two images with the same file with different exposures on the screen at the same time in the Photoshop creative cloud (in previous versions we could open two images of the same nef (raw) file and then combine them on the screen with the move tool. They have become a composite of two layers which could be developed further with the mask tool.

    Hello

    Please go to the preferences > workspace and uncheck the option 'open the document in the tabs '.

    Now you can click on file and choose file > open and open the two images in two different windows which can be arranged side by side.

    Thank you

  • Need help for reading in parallel on the same interface and writing XNET

    Hello. I need help to configure CAN interface to write and read from the same interface.

    I use NI PXI-8513/2. I use CAN1 as interface.

    My had TO send status messages CAN every 100ms. I have to read in order to return akntoowlege to keep DUT CAN interface happy and not make mistakes.

    So, I want to open Strim Session and readall frames in the loop. At the same time, I need to be able to write in a frame HAD at the time...

    I only need to read one picture at a time too, but since I know the ID, I can pull it from the stream.

    What I'm confusing all is how to put in place the same CAN1 interface to be able to write and read in parallel.

    I think I would get errors that interface is already in use.

    Since I'm new to CAN, I was read and write only when necessary. But, sometimes I was getting errors on my messages. Sometimes I get message, sometimes miss me. But, when I run CAN test criminal as sniffer he sends and written every time. I was told it's because it recognizes all messages.

    I opened to suggestions of how best to implement the interface.

    I guess I can use CAN2 and separator to work around this problem, but I would use an interface if possible.

    Thank you

    Hi Rus,

    The XNET hadrware takes care of most of the low level of detials for you. The reading and writing of the circuits are both connected to the bus at any time. When you write to the hardware it will try to put a frame on the bus at the first opportunity he can. If the frame loses arbitration material re - will attempt to send the frame up is successful. Reception equipment monitor activity on the bus, regardless of what it conveys. The material received will usually throw a framework that was sent by communication equipment, but there is an Echo property pass to circumvent this behavior too.

    Take a look at the example of the expedition: MAY-> NI - XNET-> Sessions-> multiple Sessions Intro-> CAN even exit entry framework Port unique Point.vi. Keep in mind that this example you will need to use a second CAN interface to recognize frames, it transmits. I would recoment against the example CAN output Frame Single Point which would mimic your ECU if you choose a type of cyclic frame running this example.

  • with third party applications, I can read and write on the external drive HFS + for windows?

    Hello

    I see with third party app I can read and write to external disk NTFS on the mac computer.

    then othrwise, then I can read and write on extern hardrive HFS + with application of third party windows computer.  So who are the best third-party applications to read and write HFS and if they are free of charge on the external drive?

    Thank you

    Johan

    Now that I understand your goal, check out http://www.ufsexplorer.com/rdr_hfsp.php but your YMMV.

  • Extract PDF form data using JavaScript and write in the CSV file

    I received a PDF file with a form.  The form is * not * formatted as a table.  My requirement is to extract form field values and write into a CSV file that can be imported into Excel.  I tried using the menu item "Merge data from spreadsheet files" automated in Acrobat Pro, but the release includes both the labels and values.  I'm mostly just interested in the form field values.

    I would use JavaScript to extract the data from the form and learn JavaScript write CSV file (since I know what should look like the spreadsheet of end).  I got regarding the extraction of the fields in the form:

    this.getField("Today_s_Date").value;

    And the rest of this post: http://StackOverflow.com/questions/17422514/how-to-write-a-text-file-in-Acrobat-JavaScript , I tried to write to CSV using:

    var cMyC = "abc";

    var doc = this.createDataObject ({cName: "test.txt", cValue: cMyC});

    but I get the following error:

    "SyntaxError: syntax error".

    1:Console:Exec ".

    Ideally, I don't want to use a third-party tool online to make, because the data are sensitive.  But please let me know if you have any suggestions.  The ideal output is a CSV file that an end business user can open in Excel to see the format of spreadsheet of his choice.

    Did anyone done this before?  Open to hearing alternatives as well.  Thanks in advance!

    The code you have posted works fine for me in the JavaScript console, so I suspect the problem is something else. Where did he put the code and y at - he seized another code?

    In addition, if CSV is not a strong requirement, I would say that you use delimited by tabs instead. Fields normally cannot contain tab characters, this is a good qualifier to use. It will be also more reliable when you import in Excel. If you need to process the field data that may contain quotes, you need prepare correctly the string data and can use a JavaScript library like this: https://github.com/uselesscode/ucsv

  • Questions about serial port read and write at the same time

    Hi I create a user interface for the communication serial port, where there are essentially 2 front panels, where the user enters commands one and the other where the prints of UART is delivered. I thought initially using a state machine but the reading and writing may be independent sometimes and so I can't rely on States. I searched a bit on the forum and he left me even more confused. Help, please.

    (1) in a thread that sessions visa duplicated has been used for writing and reading at the same time, is it recommendable? How will this affect performance?

    (2) essentially when the vi is reading data are it must constantly view as well, however, someone said that it takes too much memory to use shift registers, so how do I go about this? If using a State in queue after the loop of reading it affects the playback loop and be sequential?

    In addition anyway is to move the cursor to the latest data from the indicator

    (3) for the control of the user input, assumes that the user has entered an order in the control and press ENTER, then writing visa is launched, but if it comes in another string and press enter then write must be called again... is - it possible? will detect the previous commands in the control of compensation?

    (4) according to my understand the expectation for the event do not monopolize resources and writing can go in parallel, am I right?

    Thank you. I have attached a very basic vi which took me to the point, but I want to make it more robust. Please help especially in the part of the user interface.

    su_a,

    (1) you can have only one session to a port. Several UART can handle full duplex so performance is not affected.  At flow rates of high data and large amounts of data, buffering and latencies of BONE can become a problem.

    (2) who told you that shift registers using too much memory? Shift registers are usually the best way to transfer data from one iteration to another. String concatenation inside a loop (registry to offset or not) causes the chain to develop and may require re-allocation of memory.  Your VI never clears the string so its cold length become very large.

    Generally, you do not have an active cursor on an indicator.  If you want to always display the most recently received characters and turn on the vertical scroll bar use a property node to keep scrolls to the bottom.  This can be annoying for users if they attempt to manually move the scroll bar and find that the program continues to move it back automatically.

    (3) if the user has changed the value in the chain of command, when he hits enter the modified value event fires.  Simply strike brace does not change the value and does not trigger the event.  Not control need to be erased, but the value that he has to change.  If you want to send the same command again, have a button send a command may be a better choice.

    (4) write is a case of the event.  It is not in parallel with anything.  The structure of the event do not monopolize resources.  The other loop will run while it waits.

    The event loop will not stop when you press the STOP button. Probably it wll take two command: change events of value after JUDGMENT before any loop stops.  Replace the Timeout event (which never expires) with a STOP: value change event and a real wire of this judgment to the Terminal endpoint.  Remove the local variable.  Make mechanical locking when released.

    Lynn

  • Read and write to the local XML file

    Hello

    I'm trying to understand how to use the xml files saved locally. My goal is to create an xml file in the repository of the application (which has read/write permissions), add data in this file xml and re - register so that it can be retrieved whenever this is necessary.

    I want to store xml data are farily short; It has the following structure:

    
        x
        x
        x
        x
        x
        x
        x
        x
        x
        x
    
    
    
    ...etc.
    

    I read a few articles about recording and writing in a file like this, but none of them does not seem to work. I hope someone could provide me with the code to do this.

    Thank you.

    Try:

    ///////////////////////////////////////////////////////////////////////

    public public static function Store (name: String, data: String): void

    {

    var file: file = File.applicationStorageDirectory.resolvePath (name);

    var file_stream: FileStream = newFileStream();

    file_stream. Open (file, FileMode.WRITE);

    out of the var : String = '\n';

    output of +=;

    output = output.replace (\n/g, File.lineEnding);

    file_stream.writeUTFBytes (output);

    file_stream. Close();

    }

    //////////////////////////////////////////////////////////////////////////

    public public static function Get (name: String): XML

    {

    var config: XML = null;

    var file: file = File.applicationStorageDirectory.resolvePath (name);

      if (file.exists)

    {

    var file_stream: FileStream = new FileStream();

    file_stream. Open (file, FileMode.READ);

    config = new XML (file_stream.readUTFBytes (file_stream.bytesAvailable));

    file_stream. Close();

    }

    return config;

    }

  • Simple BPM with file read and write immediately to new file

    Hello

    I am trying to create a very simple process of BPM, with reading a file which is simply written again.
    For this I use a "task receive" calling the task of reading and a "service mission" to call the writing task.

    The composite.xml generated for the son looks like this:

    < component name = 'Process' >
    < implementation.bpmn src="processes/Process.bpmn"/ >
    < / component >
    < name of reference = "WriteFile" ui:wsdlLocation = "WriteFile.wsdl" >
    < interface.wsdl interface = "http://xmlns.oracle.com/pcbpel/adapter/file/Playground/Project1/WriteFile#wsdl.interface (Write_ptt)" / >
    < binding.jca config = "WriteFile_file.jca" / >
    < / reference >
    <>wire
    < source.uri > < source.uri > Process/Services.Externals.WriteFile.reference
    < target.uri > < target.uri > WriteFile
    < / thread >
    "BOLD"
    <>wire
    < source.uri > < source.uri > Process/References.Externals.ReadFile.service
    < target.uri > < target.uri > ReadFile
    < / thread >
    "BOLD"
    <>wire
    < source.uri > < source.uri > ReadFile
    < target.uri > < target.uri > Process/References.Externals.ReadFile.service
    < / thread >
    < / composite >

    When you try to deploy an error message is generated:
    Error (33,17): could not find the reference name 'References.Externals.ReadFile.service' in the 'Process' component for thread definition

    for the code shown above to
    <>wire
    < source.uri > < source.uri > Process/References.Externals.ReadFile.service
    < target.uri > < target.uri > ReadFile
    < / thread >

    Once I have remove this part of the process is ok and runs as expected.

    As it is generated code and I did nothing on the wiring, could someone tell me what I'm doing wrong?

    If you need additional information, please let me know.

    Thank you and best regards,
    ISA

    I see nothing wrong here...

    without doubt, recreating the process and I feel you should nt get that again...

    Sharma

  • Need details (fsisys, fsiuser and afgjob) of the Configuration file for an XML in documaker 12 execution

    Hello

    I need details of the basic configuration for the execution of a simple xml in documaker 12. Details such as printer, configuration of the recipient, etc..

    Hello Sen,

    You can set below the sections of XML configuration related in addition to the configuration manager of DB and the General library which is necessary for Documaker version 12.x. The configuration of the printer may not require changes from the flat file extracted mode. Make sure the entrance of afgjob; BatchingByRecipINI; is in place too.

    < extractkeyfield="">

    Masque_recherche = 1,<>

    [RECIP_NAMES]

    ZERO = 000,

    FC = 101, COPY FULL

    < batchingbyrecip="">

    DefaultBatch = BATCH1

    Batch_Recip_def =! RecipientRecord [RecipientDescription = "Full copy"]; "' BATCH1 '; FC

    < runmode="">

    NAUNLOAD = Yes

    XMLExtract = Yes

    DownLoadFAP = Yes

    ChkDstLenExceeded = No

    LoadCordFAP = No

    CheckNextRecip = No

    CompiledFAP = No

    < trn_fields="">

    SystemInd =! TransactionRecord/TransactionKey/SystemIndicator

    TransactionNum =! TransactionRecord/TransactionKey/TransactionNumber

    LOB =! PolicyRecord/LOB

    Iteration =! TransactionRecord/TransactionKey/Iteration

  • Write in the text file on request

    Hello

    I've been struggling with the "write to text file" in the part of the attached .vi button

    I want to be able to say my program when I press on the Boolean key it should collect 1 sample point only from the mean.vi - now that I managed to do a Boolean-button that starts the collection of data and then I have to press the button again when I 'think' now, I collected a data point using the structure of the case.

    Can someone help me to collect the data a not that when I press the Boolean?

    Thank you!

    Change the mechanical action of the key "lock when released.  It is an option to right click on the button on the front panel.

  • Reading single line of the text file

    I use the following code to read a .txt file

    private String readTextFile (String fName) {}
    String result = null;
    FileConnection fconn = null;
    DataInputStream is = null;
    try {}
    fconn = (FileConnection) Connector.open (fName, Connector.READ);
    is = fconn.openDataInputStream ();
    Byte [] = IOUtilities.streamToBytes (is) data;
    result = new String (data);
    } catch (IOException e) {}
    System.out.println (e.getMessage ());
    } {Finally
    try {}
    If (null! = is)

    is. Close();
    If (null! = fconn)
    fconn. Close();
    } catch (IOException e) {}
    System.out.println (e.getMessage ());
    }
    }
    return the result;
    }

    I want to print a single line instead of the file around so I read that I need to store the contents of the file into an array and then get the index of the line. Problem is that I couldn't find any information on how to do it. Can someone give me a shot. Thanks in advance.

    This isn't a problem with encoding. You just need to do a little extra accounting and adjust start and end indices to remove these characters. To treat the "\r\n" of line termination style, you can maintain a flag (initially false) to indicate that the previous line ended with a \r; If a line begins with \n, it should be treated as the end of a line (empty) if the flag is true (in which case it should be ignored).

    If you want to extract all lines (not just the first), then it may be easier to do this accounting while avoiding a separate function. Something like this (untested):

    // read the file into a byte array 'data'; then:
    Vector lines = new Vector();
    boolean endCR = false;
    int start = 0;
    for (i = start; i < data.length; ++i) {
      if (data[i] = 0xD) {
        lines.addElement(new String(data, start, i - start));
        endCR = true;
        start = i + 1;
      } else if (data[i] = 0xA) {
        if (endCR && i == start) {
          start++;
          endCR = false;
        } else {
          lines.addElement(new String(data, start, i - start));
          start = i + 1;
        }
        endCR = false;
      }
    }
    String[] results = new String[lines.size()];
    lines.copyInto(results);
    

Maybe you are looking for