Read a line in a txt file

Hi all

I need to know how to read entire of any txt file lines. For example, I have this in a txt file:

testline1

testline2

testline3

and I need to read only the line 2 (text "testline2").

I know how to read the file:

var file = File(app.activeScript.parent.fsName + '/test.txt');
file.open("r");
var str = file.read(); // whole content of "test.txt" is now in variable "str"
file.close();

but I don't know how to read ONLY for example to line 2. Can you help me with this someone please?

Thank you very much in advance

1. use the function of a file object readln: Adobe InDesign CS6 (8,0) object model JS: file

2. look in the sample scripts; FindChangeByList.jsx uses "readln".

Tags: InDesign

Similar Questions

  • 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);
    
  • How to read the Thai language in .txt file?

    AttN; Who may apply.

    How read txt file in another language (Asian language like Japanese, thai or Korea)?

    Please let me know urgent... I have to use emergency...

    Best regards

    SAE

    Hello CAs,
    Welcome to the community of Sony.

    What is the model number of the digital book reader?

    The reader supports text formats (.txt) as well as the two following formats:
    -File EPUB (.epub) EPUB (version 2.0 of PAHO) taken in charge
    -PDF file (.pdf) support is based on the PDF 1.6 specification.

    The default language on your Reader Digital Book setting does not affect the language in which the book is. Reading in a foreign language, you will have to buy them specifically in this language.

    Thank you for your message.

  • How do I skip the first 5 lines of a txt file when using sql * loader

    Hello

    I have a txt file that contains state of header information that I don't need. How can I skip this line when you import the file into my database?

    See you soon

    You can use the SKIP option: http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_params.htm#sthref626

  • How to read a line of text of 7000 characters, webutil won't

    Hi, webutil with client_text_io.get_line return ora-06502 as impossible to read the line in a txt file.

    There is a wide range.

    Can someone help me?

    Hi, I deal with utl_file database, it works.

    in_file: = UTL_FILE. Fopen (v_nomeserver, nom_fichier2, 'r', 32000);

    UTL_FILE.get_line (in_file, linebuf, 32000);

    in_file2: = UTL_FILE. Fopen (v_nomeserver, 'w', 32000, filename);

    UTL_FILE.put_Line (in_file2, linebuf);

    linebuf: = replace (linebuf, e<>

    UTL_FILE. Fclose (in_file);

    UTL_FILE. Fclose (in_file2);

  • READ TXT FILE IN STEPS

    Hello friends,

    In the past, you have helped me a lot!

    Please, I'm reading the variables in a txt file attached. Variables appear between the lines 5187 to 5236 (49 lines). Below the threshold of 5241 to 5290 (49 lines). After the same variables of the line to line 8342 8293 (49 lines) and line 8347 8396 (49 lines). Among the variables, there is a 3106 line spacing. And so on!

    The Knight of OR helped me a lot to solve part of the problem. His tips were very helpful!

    I would like some advice to unify the txt file variables in just a chart. Is this possible?

    Could change the attached vi.vi?

    Thank you


  • Remove # and clear the line from txt files

    Hello

    I have problem with my program.

    I need to remove the empy lines in my txt file.

    This is file look like:

    # Standard capacitance data file
    # Model capacity: parallel (K = 3.0)
    # Created by: ECT32v2 for Beta2.25 of Win32 (July 10, 2003 01:54:24)
    # Source: rec_flow_f45_v800_n2.bcp
    # Description: contents of the buffer to capture mode
    # Date: 12:04:43 GMT standard time, 29 March 04
    # Electrodes = 8, measures = 28
    # Data for plan 1

    # 1 frame (0 msec)
    0.006-0,001-0.004-0, 002 - 0.028-0.031-0,002
    -0.008-0, 005 - 0.007 - 0.024 0.005 0.004
    -0.014-0, 002 - 0.011-0.004 0.002
    -0.008 - 0.003 - 0.004 0.003
    -0.011 0.001 0.002
    0.005 0.004
    0,008

    # structure 2 (10 ms)
    -0.002 0, 005 - 0.008 0.006-0,002 0,023 0.011
    -0.008-0.004 - 0.004 - 0.003 0.010 0.001
    -0.007-0,001-0,012 0.007 0,008
    -0.015-0.004 0.002 0.001
    -0.007-0,002 0.001
    -0.002 0,008
    0.005

    I want to remove all empty lines, lines containing ' # '.

    I try as an attachment, but it does not work.

    How can I do this?

    Regads,
    Sorry for my English

    Ben Merci for example. Somehow, I missed the framework which enabled search expresion. Your example has sent me to the help files to understand. I have modified my first code for the show method, I hope I have the correct explanation. Not trying to do someones homework for them, but for those who need a quick start, maybe this will help someone else along the way.

  • read the specific number of the txt file

    Hello

    Anyone know how to read specific numbers to a txt file.

    If the operator choose tab1. The values displayed will be the first list of numbers. Otherwise the values shown on the table are the second list

    Thanks in advance for your help

    Please find enclosed my VI and the txt file

    My best regards

    Nadia

    The format of your example tab.txt file in do you need?

    If not, I do not consider using a format such as LabVIEW Config File VI or a common standard such as XML.

    If you don't need the exact format in the example, then you will need to write your own parser for him.

  • Read last line of a log of the file using UTL_FILE

    Hi all

    My environment is--> Oracle 11 g Database Release 1 on Windows 2003 Server SP2.
    Requirement is-> reading last line of a log file with UTL_FILE.

    I am reading the last line of a log file that is generated by our own application. I am able to get the last row using the script but the problem below is in the log file, has some blank lines at the end so I get the output as white.

    Script
    Declare
    DIRECTORY VARCHAR2 (300): = 'BACKUP ';
    name VARCHAR2 (300): = 'Client_Log_02-05 - 2011.log';
    l_file UTL_FILE.file_type;
    l_text VARCHAR2 (32767).
    BEGIN

    l_file: = UTL_FILE.fopen (DIRECTORY, filename, 'r', 32767);
    UTL_FILE.get_line (l_file, l_text, 32767);
    -DBMS_OUTPUT.put_line (' Frontline: |' | l_text |) '|');
    BEGIN
    LOOP
    UTL_FILE.get_line (l_file, l_text, 32767);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    END;
    Dbms_output.put_line (' last line: |' | l_text |) '|');
    UTL_FILE.fclose (l_file);
    END;

    Please advice me how to skip/ignore empty lines... If you have web links or scripts please share.

    Thank you for your help

    Shan

    I think that there are many ways... we have to save the last string that is not empty like this:

    DECLARE
        directory   VARCHAR2 (300) := 'BACKUP';
        filename    VARCHAR2 (300) := 'Client_Log_02-05-2011.log';
        l_file      UTL_FILE.file_type;
        l_text      VARCHAR2 (32767);
        l_text_not_null      VARCHAR2 (32767);
    BEGIN
        l_file :=
            UTL_FILE.fopen (directory,
                            filename,
                            'r',
                            32767);
        UTL_FILE.get_line (l_file, l_text, 32767);
    
        BEGIN
            LOOP
                UTL_FILE.get_line (l_file, l_text, 32767);
                IF REPLACE (REPLACE (TRIM (l_text), CHR (10)), CHR (13)) IS NOT NULL THEN
                   l_text_not_null := l_text;
                END IF;
            END LOOP;
        EXCEPTION
            WHEN NO_DATA_FOUND
            THEN
                NULL;
        END;
        DBMS_OUTPUT.put_line ('Last Line : |' || NVL(l_text_not_null, l_text) || '|');
        UTL_FILE.fclose (l_file);
    END;
    
  • How to display random lines from txt file

    Good morning (or evening all). I am creating an application and want to display random lines of a text file. I know how to create a text file using file connections, but how can I read the random lines of her?

    OK I got it.

    For beginners like me to have a problem in the future, I was not specify my path correctly. It is not enough to land your .txt in the /res folder and wait for the Simulator to load. You must load from SD card or device memory.

    Use the method found here:

    http://www.weask.us/entry/J2ME-BlackBerry-read-write-text-file

    to use it's as simple as that

    StringfName = "file:///SDCard/Blackberry/text.txt";

    String printLine = readTextFile (fName);

    label.setText (printLine);

    Somewhere in your project directory create a directory called SDCard (I did in my res folder).

    In the Simulator go to switch SD card, then load Select Directory and select the new directory of the SD card. This will create the structure of the SD card in the Simulator. Simply move your .txt in the SDCard/Blackberry directory and run your application.

  • UTL_FILE to read a txt file? error

    Hello.
    I'm tring to read the data in outputfile. TXT file when the data are several lines
    the followig PL/SQL works well. BUT the problem when the outputfile. TXT file
    has a long lineage (maybe 500 words). I got this error.



    My problem of long line or another problem, but I can't make it. ?


    SQL > create an output directory as "c:\output";
    create an output directory as "c:\output".
    *

    SQL > grant read, write on the output of the ayham1 directory
    2
    SQL > declare
    2 f utl_file.file_type;
    3S CLOB;
    4 start
    5 f: = utl_file.fopen('OUTPUT','outputfile.txt','R');
    6 loop
    7 utl_file.get_line(f,s);
    8 dbms_output.put_line (s);
    9 end of the loop;
    10 exceptional
    When 11 NO_DATA_FOUND then
    12 utl_file.fclose (f);
    13 end;
    14
    15
    16.
    declare
    *
    ERROR on line 1:
    ORA-29284: error reading file
    ORA-06512: at "SYS." UTL_FILE", line 106
    ORA-06512: at "SYS." UTL_FILE", line 746
    ORA-06512: at line 7

    FYI outputfile. TXT does not create by me. It always creates on the other system.

    Published by: Isabelle Sep 17, 2012 01:49

    Hello

    Assuming that the file itself readable, you can try using the fourth parameter of FOPEN.

    declare
    f utl_file.file_type;
    s CLOB;
    begin
    f := utl_file.fopen('OUTPUT','outputfile.txt','R',32767);
    loop
    utl_file.get_line(f,s);
    dbms_output.put_line(s);
    end loop;
    utl_file.fclose(f);
    end;
    

    Kind regards
    Ousseni

  • Read a .txt file

    I try to know how to read a .txt file and simply set its contents to a variable. Is this possible?

    [Edit] right after the announcement that I found this page which seems like it could be in the sense that I want to go but I have not checked completely yet: http://ExtendScript.blogspot.com/2009/06/read-tab-delimited-text-file.html

    Just post the link for future researchers or if someone will say ' Hey! This isn't what you're looking for! "

    For anyone interested, was the answer to me:

    var fileToParse = file ('path');

    fileToParse.open ('r');

    var dataToGet = fileToParse.readln ();

    fileToParse.close ();

    I need only the line, that's why my example above is so simple.

  • Read the lines of the file of the file

    Hello, I followed the example of the http://odiexperts.com/?p=918 here but I get you lines of the file. I want to read these lines and store it in the database.

    First, I created a new procedure, with 2 stages and 1 option (called 'count' predefined: 0), then:

    ----------------------------------------------------------------------------------------------
    Step 1:

    Command in the Source file
    Command on target Jython

    filesrc = open('c:\\path\\filename.tag','r')
    first = filesrc.readline)
    lines = 0
    all first:
    lines += 1
    first = filesrc.readline)
    filesrc. Close()
    County = lines
    If the < 1 lines:
    raise "\n cannot further process the file contains lines"

    Step 2:

    Command on the Source undefined
    Command on target Oracle

    INSERT IN TEMP_ROWS_COUNT ('header_count', 'body_count', 'foot_count', 'session') VALUES (#header_num_rows, '< % = odiRef.getOption ("count") % >', #foot_num_rows, '< %=odiRef.getSession ("SESS_NO") % >')

    ----------------------------------------------------------------------------------------------

    When I run this procedure, it will return no error, but the result of 'count' is always 0. Other values are ok.

    What I am doing wrong?

    Thank you.

    Hi Angel,

    I wrote the jython script to modify according to your needs. I hope this helps.

    # importing required libraries 
    
    import os
    import string
    import java.sql as sql
    import java.lang as lang
    import re
    
    # program to read the file 
    
    filesrc=open('/home/oracle/test_script.txt','r')
    lines=0
    first=filesrc.readline()
    while first:
         lines +=1
         first=filesrc.readline()
    
    filesrc.close()
    count=lines
    
    # PROGRAM TO INSERT INTO TABLE 
    
    sourceConnection = odiRef.getJDBCConnection("SRC")
    sqlstring = sourceConnection.createStatement()
    sqlstmt= "INSERT INTO ODI_TEMP.TEMP_ROWS_COUNT VALUES ('header','"+ str(count) +"','footer','<%=odiRef.getSession("SESS_NO")%>')"
    
    sqlstring.executeUpdate(sqlstmt)
    
    sourceConnection.close()
    

    Please change the name of the ODI_TEMP to your required schema schema,
    also change the header and footer of your required variables

    co-pilot on source - choose the technology database where there are the TEMP_ROWS_COUNT and the required schema
    and in order to target the above codes.

    I hope this helps. Please let me know if you need any help or code change more to incorporate any logic.

    Thank you
    Dev

  • Import data from txt file with the reading of the names of columns

    Hello

    After changing the export of my simulation program, I can't use the postet heresolution, that works well. (I mark the message as hailed this is why I run a post only)

    Can anybode if you please tell me how to fan the code to import the new txt file type. The names of the columns here are FOA online first columns, like this (with ignoring the first lines).

    Hello Gabriel

    You can use the use wizard (Navigator > file > use wizard) to define a new filter to import file for your data. It will take only a minute.

    Please find the uri of the file that I create for you. Copy the attached file in your disk, unzip it and double-click the file uri.

    Then you can open your file by using 'open with '.

    Hope this helps

  • Cannot read txt file correctly on the cRIO RT after deployment system

    As shown in attachment VI works fine on my system cRIO9073 during execution of the Project Explorer and press the arrow. But unfortunately it no longer works when it is deployed (having a build). This VI is part of a larger project, but I was able to trace the issue to this VI, where something goes wrong with the reading of the text file. I now use the case of fake (not shown), where I have temporary added the txt file content in a string constant. Of course, it's a good solution, but not flexible.

    Anyone have an idea what's not here?

    I use NEITHER-RIO 3.1.0 - January 2009 version as the version of the software on the cRIO system.

    Hello

    I don't know that you still have this issue, but I think that you cannot use this property (axis type) node in your cRIO. If please remove it and try again to see what would be the influence.

    I'll hear it on your part.

    Kind regards

    Hossein

Maybe you are looking for

  • Portege R100: No restore CD - is WinXP installation possible?

    Hello! I had recently a well used old Portege R100 with a Toshiba PCMCIA CD that comes with it. He unfortunately did not come with the recovery CD and the hard drive has been formatted to him! I tried to install WinXP Pro many times now come to the c

  • Impossible to browse and an IIS Site

    I'm trying to browse an IIS site that is hosted on a web server to an application server in the same domain. The web site is https and I can access it from the server web host and a different network. Since the application server, I can ping the dns

  • How to remove startup programs

    original tiitle: I'm trying to remove some programs on the start menu to the top, __But I can't find the start of the manu I'm trying to remove some programs from the start menu But I can't find the start of the manu

  • Library of Windows media player 11

    my photos and albums photos somehow were transferred to the library in Windows Media Player and I can't move back to my original hard drive. (I have baby pictures I need to the rescue!) Help, please!

  • App store pending purchase

    Recently, I tried to buy 2 apps using my standard credit card. First "tried" apps and I loved them so I wanted to buy. I went through the purchase screens and then nothing happened. Applications still tell me I have to buy to use all the features. I