Import Script to skip first 6 lines of a txt file

Hello,
Can anybody help me here? I am looking for an Import Script in Upstream that will ignore the first 6 lines of the TXT file I am importing. FYI - The first 6 lines is the header and I don't want this to be imported as it results in error.
Can you help? Thanks,
James

Even with fixed format files you shouldn't be getting error for the header lines in the file because there is no amount in those lines,, however if you are still getting the error, you can try this, it may help,
There are temporary variables you can use for this kind of needs: RES.PvarTemp1 to 5
so, you will need to put a script in amount field, let's say "getLineNumber"
function getlinenumber
If Len(RES.PvarTemp1) <= 6 Then
RES.PvarTemp1 = RES.PvarTemp1 & "1"
RES.PblnSkip = True
End If
end function
this should do the work, if you are using RES.PvarTemp1 for other purposes in your scripts, use another temp variable.
hope this helps
Bulent
Edited by: Bulent Yildiz on Oct 26, 2009 4:59 PM
Edited by: Bulent Yildiz on Oct 26, 2009 5:02 PM

Similar Messages

  • How to skip certain lines for a txt file and insert into array

    so here is my question:
    i had a file to read, and it requires to input into the array starting from a certain line
    example:
    4
    john 25 M
    mary 22 F
    lee 20 M
    faye 10 F
    faye john
    mary john
    mary faye
    i want to insert the friend list, starting 5th line into a 2d array, which is the int from first line +1.
    can someone help me with it?
    i believe there is a skip method and stuff..
    but just dont know how to use it
    may someone tell me how to do tat?

    the thing is i think that takes too long and it is not efficient..
    however...i just solved it with a better method
    Scanner in = new Scanner (reader);
    int size = Integer.parseInt(in.next());
    BufferedReader insert = new BufferedReader(new FileReader(new File(input)));
    String line = null;
    int count = 0;
    int startAtLineNo =size+1; // 0-based
    while ((line = insert.readLine()) != null) {
    if (count >= startAtLineNo) {
    /* do stuff */
    System.out.println(line);
    // else ignore
    count++;
    thanks anyways

  • File Sender Adapter Skip first line in file

    Hello to all,
    I'm trying to read a file (nfs) using the file adapter.
    The szenario works fine, but I need to skip the first line in the txt file (header line)
    I tried parameter documentSkipFirstRows, without success.
    Any ideas?
    Regards Christian

    Hi Kaiser,
    May be the syntax problem.
    use like this...
    xml.documentSkipFirstRows     1
    Syntax is
    xml.documentSkipFirstRows=<noOfRows>
    for more info refer this link..
    http://saphelp.border-states.com/EN/0d/00453c91f37151e10000000a11402f/frameset.htm
    Verify this...
    Thanks.

  • Delete a line in a .txt file

    Hi, i would delete the first line of a .txt file but i don't understand wich kinf of java.io object i have to use. Now i'm trying to work with BufferedReader in this code:
    BufferedReader in = new BufferedReader(new FileReader(file));
    int len;
    len = in.readLine().length();     
    StringBuffer lineSB= new StringBuffer(in.readLine());
    lineSB.delete(0,lineSB.length());
    PrintWriter out = new PrintWriter(new FileWriter(file));
    out.close();
    in.close();
    ...but the file is cancelled totally. Please help me!

    Here is your code, with comments about what you are doing:
    StringBuffer lineSB= new StringBuffer(in.readLine());
    lineSB.delete(0,lineSB.length()); // delete the entire string buffer (not file)
    PrintWriter out = new PrintWriter(new FileWriter(file)); // creating a new printWriter for an entirely new file with the -name- in string file (no relation to previous file)what you need to do is something like this:
    in.readLine(); // discard the first line
    String s = in.readLine(); // get the next line
    PrintWriter p = new PrintWriter(new FileWriter(newFileName));
    while(in != null) {
      p.out(s); // write each line back out to the new file
      s = in.readLine();
    }Hope this helps.
    - amber

  • Could not parse the file contents as a data set. There were too many variable names in the first line of the text file.

    Could not parse the file contents as a data set. There were too many variable names in the first line of the text file.

    What are the Variables settings, what is the text file’s content, …?

  • Creating a JButton for each line in a txt file

    I need to know how to creating a JButton for each line in a txt file then add an actionListener to the number of buttons (note they are in a JTable). Here is a clipet of code thanx for the help (note that this is one part of a program i am making there are 2 more classes. If u need them just ask) Thanx:
    class Diary extends JFrame implements ActionListener {
         private JTextArea note;
         private JTextField name;
         private JMenuBar menu = new JMenuBar();
         private JMenu file, edit, font, background, tcolor, settings, help;
         private JMenuItem nu, copy, paste, save, exit, b8, b10, b12, b14, b16, b18, b20, b24, b30, bblue, bred, bgreen, bpink, cblue, cred, cgreen, cpink, eset, nver, using, about;
         private String[] columnNames = {
              "File"
         private Vector dat = new Vector();
         private JTable filetable;
         public Diary() {
              setSize(new Dimension(500, 500));
              setTitle("Diary 2.00");
              file = new JMenu("File");
              menu.add(file);
              nu = new JMenuItem("new");
              nu.addActionListener(this);
              file.add(nu);
              file.add(new JSeparator());
              copy = new JMenuItem("copy");
              copy.addActionListener(this);
              file.add(copy);
              paste = new JMenuItem("paste");
              paste.addActionListener(this);
              file.add(paste);
              file.add(new JSeparator());
              save = new JMenuItem("Save");
              save.addActionListener(this);
              file.add(save);
              file.add(new JSeparator());
              exit = new JMenuItem("exit");
              exit.addActionListener(this);
              file.add(exit);
              edit = new JMenu("Edit");
              menu.add(edit);
              font = new JMenu("font");
              edit.add(font);
              b8 = new JMenuItem("8");
              b8.addActionListener(this);
              font.add(b8);
              b10 = new JMenuItem("10");
              b10.addActionListener(this);
              font.add(b10);
              b12 = new JMenuItem("12");
              b12.addActionListener(this);
              font.add(b12);
              b14 = new JMenuItem("14");
              b14.addActionListener(this);
              font.add(b14);
              b16 = new JMenuItem("16");
              b16.addActionListener(this);
              font.add(b16);
              b18 = new JMenuItem("18");
              b18.addActionListener(this);
              font.add(b18);
              b20 = new JMenuItem("20");
              b20.addActionListener(this);
              font.add(b20);
              b24 = new JMenuItem("24");
              b24.addActionListener(this);
              font.add(b24);
              b30 = new JMenuItem("30");
              b30.addActionListener(this);
              font.add(b30);
              background = new JMenu("background");
              edit.add(background);
              bblue = new JMenuItem("blue");
              bblue.addActionListener(this);
              background.add(bblue);
              bred = new JMenuItem("red");
              bred.addActionListener(this);
              background.add(bred);
              bgreen = new JMenuItem("green");
              bgreen.addActionListener(this);
              background.add(bgreen);
              bpink = new JMenuItem("pink");
              bpink.addActionListener(this);
              background.add(bpink);
              tcolor = new JMenu("text color");
              edit.add(tcolor);
              cblue = new JMenuItem("blue");
              cblue.addActionListener(this);
              tcolor.add(cblue);
              cred = new JMenuItem("red");
              cred.addActionListener(this);
              tcolor.add(cred);
              cgreen = new JMenuItem("green");
              cgreen.addActionListener(this);
              tcolor.add(cgreen);
              cpink = new JMenuItem("pink");
              cpink.addActionListener(this);
              tcolor.add(cpink);
              settings = new JMenu("Settings");
              menu.add(settings);
              eset = new JMenuItem("Edit Settings");
              eset.addActionListener(this);
              settings.add(eset);
              help = new JMenu("Help");
              menu.add(help);
              using = new JMenuItem("Using");
              using.addActionListener(this);
              help.add(using);
              about = new JMenuItem("About");
              about.addActionListener(this);
              help.add(about);
              help.add(new JSeparator());
              nver = new JMenuItem("new Versions");
              nver.addActionListener(this);
              help.add(nver);
              note = new JTextArea("");
              try {
                   BufferedReader filein = new BufferedReader(new FileReader("files.txt"));
                   String sfile;
                   while ((sfile = filein.readLine()) != null) {
                        //add buttons per each line of the txt file and show em
              catch (FileNotFoundException ioe) {
                   JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);
              catch (IOException ioe) {
                   JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);
              String[][] data = new String[dat.size()][];
              for (int x = 0; x < dat.size(); x++) {
                   data[x] = (String[])dat.get(x);
              filetable = new JTable(data, columnNames);
              filetable.setPreferredScrollableViewportSize(new Dimension(100, 500));
              JScrollPane scrollpane = new JScrollPane(filetable);
              name = new JTextField("diary");
              JPanel main = new JPanel(new GridLayout(0, 1));
              getContentPane().add(note);
              getContentPane().add(name, BorderLayout.SOUTH);
              getContentPane().add(scrollpane, BorderLayout.WEST);
              setJMenuBar(menu);
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == nu) {
                   int nuask = JOptionPane.showConfirmDialog(Diary.this, "Are you sure you want to make a new entry?\nThis will erease any unsaved entry's!!");
                   if (nuask == JOptionPane.YES_OPTION) {
                        note.setText("");
                        note.setBackground(Color.WHITE);
                        note.setForeground(Color.BLACK);
              if (e.getSource() == copy) {
                   note.copy();
              if (e.getSource() == paste) {
                   note.paste();
              if (e.getSource() == save) {
                   try {
                        String sn = name.getText();
                    FileWriter outputStream = new FileWriter("saved/" + sn + ".txt");                            
                    setTitle("Diary 1.00 : " + sn);
                    outputStream.write(note.getText());
                    outputStream.close();
                catch(IOException ioe) {
                     System.out.println("IOException");
              if (e.getSource() == exit) {
                   int exitask = JOptionPane.showConfirmDialog(Diary.this, "Are you sure you want to exit? Any unsaved entries will be deleted");
                   if (exitask == JOptionPane.YES_OPTION) {
                        System.exit(0);
              if (e.getSource() == b8) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),8));
              if (e.getSource() == b10) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),10));
              if (e.getSource() == b12) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),12));
              if (e.getSource() == b14) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),14));
              if (e.getSource() == b18) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),18));
              if (e.getSource() == b20) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),20));
              if (e.getSource() == b24) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),24));
              if (e.getSource() == b30) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),30));
              if (e.getSource() == bblue) {
                   note.setBackground(Color.BLUE);
              if (e.getSource() == bred) {
                   note.setBackground(Color.RED);
              if (e.getSource() == bgreen) {
                   note.setBackground(Color.GREEN);
              if (e.getSource() == bpink) {
                   note.setBackground(Color.PINK);
              if (e.getSource() == cblue) {
                   note.setForeground(Color.BLUE);
              if (e.getSource() == cred) {
                   note.setForeground(Color.RED);
              if (e.getSource() == cgreen) {
                   note.setForeground(Color.GREEN);
              if (e.getSource() == cpink) {
                   note.setForeground(Color.PINK);
              if (e.getSource() == eset) {
                   new UserSettings().setVisible(true);
              if (e.getSource() == about) {
                   JOptionPane.showMessageDialog(null, "Created by Collin Doering 2005 in Gr.9\n\nErrors:\n------------------------------------------------------------------\n1. No File Encryption\n2. No user and password Encryption", "", JOptionPane.INFORMATION_MESSAGE );
              if (e.getSource() == nver) {
                   JOptionPane.showMessageDialog(null, "New Version |3.00| expected July, 2005\n\nNew Features\n----------------------------------------------\n1. File Encryption\n2. User File Encryption\n3. Full help dialog\n4. More Text changing features", "", JOptionPane.INFORMATION_MESSAGE);
              if (e.getSource() == using) {
                   JOptionPane.showMessageDialog(null, "Go ask Collin Doering\[email protected]", "", JOptionPane.INFORMATION_MESSAGE );
    THANK YOU

    so i still do not understand how i would create one
    button per each line in a txt flle then read in the
    file that the txt file specified.This assumes you know how many lines there are in the file.
    If not, modify as per my prior post
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      String[] linesInFile = {"Hello","World","Goodbye","Now"};
      JButton[] btn = new JButton[linesInFile.length];
      public Testing()
        setLocation(200,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel jp = new JPanel(new GridLayout(0,1));
        for(int x = 0; x < btn.length; x++)
          btn[x] = new JButton(linesInFile[x]);//<---this would be where file.readLine() goes
          jp.add(btn[x]);
          btn[x].addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae){
              JOptionPane.showMessageDialog(getContentPane(),ae.getActionCommand());}});
        getContentPane().add(jp);
        pack();
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • How to read the last line in a txt file?

    Dear all,
    I want to read the last line in a txt file. There are thousands of lines in this file. What I want is to move the file pointer directly to the last line of the file. But I did not know how do to it. Can anybody help me out?
    Thank you very much!

    If the file is coded as ASCII or one of the encodings that maps a single byte to a char then the following class will assist you
    import java.io.*;
    import java.util.*;
    public class GetLinesFromEndOfFile
        static public class BackwardsFileInputStream extends InputStream
            public BackwardsFileInputStream(File file) throws IOException
                assert (file != null) && file.exists() && file.isFile() && file.canRead();
                raf = new RandomAccessFile(file, "r");
                currentPositionInFile = raf.length();
                currentPositionInBuffer = 0;
            public int read() throws IOException
                if (currentPositionInFile <= 0)
                    return -1;
                if (--currentPositionInBuffer < 0)
                    currentPositionInBuffer = buffer.length;
                    long startOfBlock = currentPositionInFile - buffer.length;
                    if (startOfBlock < 0)
                        currentPositionInBuffer = buffer.length + (int)startOfBlock;
                        startOfBlock = 0;
                    raf.seek(startOfBlock);
                    raf.readFully(buffer, 0, currentPositionInBuffer);
                    return read();
                currentPositionInFile--;
                return buffer[currentPositionInBuffer];
            public void close() throws IOException
                raf.close();
            private final byte[] buffer = new byte[4096];
            private final RandomAccessFile raf;
            private long currentPositionInFile;
            private int currentPositionInBuffer;
        public static List<String> head(File file, int numberOfLinesToRead) throws IOException
            return head(file, "ISO-8859-1" , numberOfLinesToRead);
        public static List<String> head(File file, String encoding, int numberOfLinesToRead) throws IOException
            assert (file != null) && file.exists() && file.isFile() && file.canRead();
            assert numberOfLinesToRead > 0;
            assert encoding != null;
            LinkedList<String> lines = new LinkedList<String>();
            BufferedReader reader= new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
            for (String line = null; (numberOfLinesToRead-- > 0) && (line = reader.readLine()) != null;)
                lines.addLast(line);
            reader.close();
            return lines;
        public static List<String> tail(File file, int numberOfLinesToRead) throws IOException
            return tail(file, "ISO-8859-1" , numberOfLinesToRead);
        public static List<String> tail(File file, String encoding, int numberOfLinesToRead) throws IOException
            assert (file != null) && file.exists() && file.isFile() && file.canRead();
            assert numberOfLinesToRead > 0;
            assert (encoding != null) && encoding.matches("(?i)(iso-8859|ascii|us-ascii).*");
            LinkedList<String> lines = new LinkedList<String>();
            BufferedReader reader= new BufferedReader(new InputStreamReader(new BackwardsFileInputStream(file), encoding));
            for (String line = null; (numberOfLinesToRead-- > 0) && (line = reader.readLine()) != null;)
                // Reverse the order of the characters in the string
                char[] chars = line.toCharArray();
                for (int j = 0, k = chars.length - 1; j < k ; j++, k--)
                    char temp = chars[j];
                    chars[j] = chars[k];
                    chars[k]= temp;
                lines.addFirst(new String(chars));
            reader.close();
            return lines;
        public static void main(String[] args)
            try
                File file = new File("/usr/share/dict/words");
                int n = 10;
                    System.out.println("Head of " + file);
                    int index = 0;
                    for (String line : head(file, n))
                        System.out.println(++index + "\t[" + line + "]");
                    System.out.println("Tail of " + file);
                    int index = 0;
                    for (String line : tail(file, "us-ascii", n))
                        System.out.println(++index + "\t[" + line + "]");
            catch (Exception e)
                e.printStackTrace();
    }Note, the EOL characters are treated as line separators so you will probably need to read the last two lines (think about it for a bit).

  • Count the number of lines in a txt file

    I need to count the number of lines in a txt file, but I can't do it using readLine(). This is because the txt file is double spaced. readLine() returns null even if it is not the end of the file. thanks for the help

    I need to count the number of lines in a txt file,
    but I can't do it using readLine(). Then just compare each single byte or char to the newline (code 10).
    This is because the txt file is double spaced. readLine() returns
    null even if it is not the end of the file.Errm what? What do you mean by "double spaced"? Method readLine() should only return null if there's nothing more to read.

  • URGENT! I need to compare a String with a line in a .txt file

    I'm a college student and I have a very simple question i guess. I need to write an if procedure which compares if a line of a .txt file is equal to something, but I just don't know how to do it. HELP!

    What specifically are you asking for? How to compare two strings?
    String s = "cat";
    String t = "Cat";
    if (s.equals(t))
       System.out.println('They are equal');    // does not print out
    if (s.equalsIgnoreCase(t))
       System.out.println('They are equal');    // prints out

  • How to skip first 5 lines from a txt file when using sql*loader

    Hi,
    I have a txt file that contains header info tat i dont need. how can i skip those line when importing the file to my database?
    Cheers

    Danny Fasen wrote:
    I think most of us would process this report using pl/sql:
    - read the file until you've read the column headers
    - read the account info and insert the data in the table until you have read the last account info line
    - read the file until you've read a new set of column headers (page 2)
    - read the account info and insert the data in the table until you have read the last account info line (page 2)
    - etc. until you reach the total block idenfitied by Count On-line ...
    - read the totals and compare them with the data inserted in the tableOr maybe like this...
    First create an external table to read the report as whole lines...
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE TABLE ext_report (
      2    line VARCHAR2(200)
      3          )
      4  ORGANIZATION EXTERNAL (
      5    TYPE oracle_loader
      6    DEFAULT DIRECTORY TEST_DIR
      7    ACCESS PARAMETERS (
      8      RECORDS DELIMITED BY NEWLINE
      9      BADFILE 'bad_report.bad'
    10      DISCARDFILE 'dis_report.dis'
    11      LOGFILE 'log_report.log'
    12      FIELDS TERMINATED BY X'0D' RTRIM
    13      MISSING FIELD VALUES ARE NULL
    14      REJECT ROWS WITH ALL NULL FIELDS
    15        (
    16         line
    17        )
    18      )
    19      LOCATION ('report.txt')
    20    )
    21  PARALLEL
    22* REJECT LIMIT UNLIMITED
    SQL> /
    Table created.
    SQL> select * from ext_report;
    LINE
    x report page1
    CDC:00220 / Sat Aug-08-2009 xxxxp for 02/08/09 - 08/08/09 Effective Date 11/08/09 Wed Sep-30-2009 08:25:43
    Bill to
    Retailer Retailer Name                  Name on Bank Account           Bank ABA   Bank Acct            On-line Amount  Instant Amount  Total Amount
    ======== ============================== ============================== ========== ==================== =============== =============== ===============
    0100103  BANK Terminal                  raji                           123456789  123456789            -29,999.98    9 0.00         99 -29,999.98
    0100105  Independent 1                  Savings                        123456789  100000002            -1,905.00     9 0.00         99 -1,905.00
    0100106  Independent 2                  system                         123456789  100000003            -800.00       9 -15.00       99 -815.00
    LARGE SPACE
    weekly_eft_repo 1.0 Page: 2
    CDC:00220 / Sat Aug-08-2009 Weekly EFT Sweep for 02/08/09 - 08/08/09 Effective Date 11/08/09 Wed Sep-30-2009 08:25:43
    Bill to
    Retailer Retailer Name Name on Bank Account Bank ABA Bank Acct On-line Amount Instant Amount Total Amount
    ======== ============================== ============================== ========== ==================== =============== =============== ===============
    Count On-line Amount Instant Amount Total Amount
    ============== ====================== ====================== ======================
    Debits 0 0.00 0.00 0.00
    Credits 3 -32,704.98 -15.00 -32,719.98
    Totals 3 -32,704.98 -15.00 -32,719.98
    Total Tape Records / Blocks / Hash : 3 1 37037034
    End of Report
    23 rows selected.Then we can check we can just pull out the lines of data we're interested in from that...
    SQL> ed
    Wrote file afiedt.buf
      1  create view vw_report as
      2* select line from ext_report where regexp_like(line, '^[0-9]')
    SQL> /
    View created.
    SQL> select * from vw_report;
    LINE
    0100103  BANK Terminal                  raji                           123456789  123456789            -29,999.98    9 0.00         99 -29,999.98
    0100105  Independent 1                  Savings                        123456789  100000002            -1,905.00     9 0.00         99 -1,905.00
    0100106  Independent 2                  system                         123456789  100000003            -800.00       9 -15.00       99 -815.00And then we adapt that view to extract the data from those lines as actual columns...
    SQL> col retailer format a10
    SQL> col retailer_name format a20
    SQL> col name_on_bank_account format a20
    SQL> col online_amount format 999,990.00
    SQL> col instant_amount format 999,990.00
    SQL> col total_amount format 999,990.00
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace view vw_report as
      2  select regexp_substr(line, '[^ ]+', 1, 1) as retailer
      3        ,trim(regexp_replace(regexp_substr(line, '[[:alpha:]][[:alnum:] ]*[[:alpha:]]', 1, 1), '(.*) +[^ ]+$', '\1')) as retailer_name
      4        ,trim(regexp_replace(regexp_substr(line, '[[:alpha:]][[:alnum:] ]*[[:alpha:]]', 1, 1), '.* ([^ ]+)$', '\1')) as name_on_bank_account
      5        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 1)) as bank_aba
      6        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 2)) as bank_account
      7        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 3),'999,999.00') as online_amount
      8        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 5),'999,999.00') as instant_amount
      9        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 7),'999,999.00') as total_amount
    10* from (select line from ext_report where regexp_like(line, '^[0-9]'))
    SQL> /
    View created.
    SQL> select * from vw_report;
    RETAILER   RETAILER_NAME        NAME_ON_BANK_ACCOUNT   BANK_ABA BANK_ACCOUNT ONLINE_AMOUNT INSTANT_AMOUNT TOTAL_AMOUNT
    0100103    BANK Terminal        raji                  123456789    123456789    -29,999.98           0.00   -29,999.98
    0100105    Independent 1        Savings               123456789    100000002     -1,905.00           0.00    -1,905.00
    0100106    Independent 2        system                123456789    100000003       -800.00         -15.00      -815.00
    SQL>I couldn't quite figure out the "9" and the "99" data that was on those lines so I assume it should just be ignored. I also formatted the report data to fixed columns width in my external text file as I'd assume that's how the data would be generated, not that that would make much difference when extracting the values with regular expressions as I've done.
    So... something like that anyway. ;)

  • Email attachment with .txt file (first line blank in the file)

    Hi all ,
    Iam trying attach .txt file to email , the file that iam accessing from server  . But first line blank (extra) even though i dont have blank line in original file .Can any help me out to resolve this issue?
    <u>Example</u> original file
    12345     aa    pq
    <u>Email attachment file</u>
                                        -> This line
    12345     aa    pq
    This is my code:
    REPORT  ZTEST_FILE  .
    DATA:BEGIN OF t_upload occurs 0,
           matnr LIKE zwplcsmev-matnr,
           zwgehrrg LIKE zwplcsmev-zwgehrrg,
           zwgehrct LIKE zwplcsmev-zwgehrct,
           zwgbev LIKE   zwplcsmev-zwgbev,
           zwpldt LIKE zwplcsmev-zwpldt,
           zwacdt LIKE zwplcsmev-zwacdt,
         END OF t_upload.
    *DATA:  maildata type sodocchgi1.
    *DATA:  mailtxt type table of solisti1 with header line.
    *DATA:  mailrec type table of somlrec90 with header line.
    DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:REC(80) TYPE C.
    DATA g_mask(20) TYPE c VALUE ',., ..'.
    DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:P_ERROR(3).
    DATA:P_REFO(3).
    DATA:   gd_error TYPE sy-subrc,
            gd_reciever TYPE sy-subrc.
    DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
            t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
            t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            w_cnt TYPE i,
            w_sent_all(1) TYPE c,
            w_doc_data LIKE sodocchgi1.
    selection-screen begin of block b1 with frame title text-001.
    parameters:p_file type localfile.
    parameter:p_email type ad_smtpadr.
    selection-screen end of block b1.
    --At Selection-Screen- -
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'TB_LIMIT_WS_FILENAME_GET'
          EXPORTING
            def_filename     = p_file
            mask             = g_mask
         mode             = 'S'
            title            = 'INPUT FILE'
          IMPORTING
            filename         = p_file
          EXCEPTIONS
            selection_cancel = 1
            selection_error  = 2
            OTHERS           = 3.
      IF sy-subrc <> 0.
           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    START-OF-SELECTION.
      PERFORM process_file.
      if p_error = 'X' AND P_REFO <> 'X'.
      PERFORM populate_message_body.
      ENDIF.
      IF P_REFO = 'X' AND P_ERROR <> 'X'.
      it_message = 'Please find Attached file'.
      APPEND it_message.
      PERFORM send_attachment tables it_message
                                 it_attach
                          using  p_email
                         'Crest to Plc Data'
                                          'TXT'
                                          p_file
                                 changing gd_error
                                          gd_reciever.
      ENDIF.
      Instructs mail send program for SAPCONNECT to send email(rsconn01)
    PERFORM initiate_mail_execute_program.
    END-OF-SELECTION.
    *&      Form  process_file
          text
    FORM process_file.
    *CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
                con_tab TYPE x VALUE '09'.   "OK for non Unicode
      DATA :l_path TYPE  string.
      l_path = p_file.
    CONSTANTS:  con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB
      con_cret type c value cl_abap_char_utilities=>newline.
    OPEN DATASET P_FILE  FOR INPUT IN TEXT MODE encoding default.
    if sy-subrc = 0.
    do.
    read dataset p_file into IT_ATTACH.
    IF SY-SUBRC  NE 0 .
    EXIT.
    ELSE.
    T_UPLOAD = IT_ATTACH.
    CONCATENATE con_cret it_attach  INTO it_attach .
    append it_attach.
    clear it_attach.
    P_REFO = 'X'.
    APPEND T_UPLOAD .
    clear t_upload.
    ENDIF.
    ENDDO.
    else.
    p_error = 'X'.
    ENDIF.
    ENDFORM.                    "process_file
    *&      Form  populate_message_body
          text
    FORM populate_message_body.
    w_doc_data-obj_name = 'TEST'.
      w_doc_data-obj_descr = 'Crest to Plc Data'.
      w_doc_data-obj_langu = sy-langu.
      it_message = 'File Not Found'.
      APPEND it_message.
    t_receivers-receiver = p_email.
      t_receivers-rec_type = 'U'.
      append t_receivers.
      call function 'SO_NEW_DOCUMENT_SEND_API1'
           exporting
                document_data              = w_doc_data
                document_type              = 'RAW'
                put_in_outbox              = 'X'
           tables
                object_header              = it_message
                object_content             = it_message
                receivers                  = t_receivers
           exceptions
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                others                     = 8.
        if sy-subrc = 0.
      commit work.
        SUBMIT rsconn01 USING SELECTION-SET 'SAP&CONNECTINT' AND RETURN.
      else.
        MESSAGE s027(vv) WITH 'E-mail not sent'.
      endif.
    ENDFORM.                    "populate_message_body
    *&      Form  send_attachment
          text
    FORM send_attachment tables pit_message
                                pit_attach
                         using  p_email
                                p_mtitle
                                p_format
                                p_filename
                                p_attdescription
                                p_sender_address
                                p_sender_addres_type
                       changing p_error
                                p_reciever.
      DATA:   ld_error    TYPE sy-subrc,
              ld_reciever TYPE sy-subrc,
              ld_mtitle LIKE sodocchgi1-obj_descr,
              ld_email LIKE  somlreci1-receiver,
              ld_format TYPE  so_obj_tp ,
              ld_attdescription TYPE  so_obj_nam ,
              ld_attfilename TYPE  so_obj_des ,
              ld_sender_address LIKE  soextreci1-receiver,
              ld_sender_address_type LIKE  soextreci1-adr_typ,
              ld_receiver LIKE  sy-subrc.
      ld_email  = p_email.
      ld_mtitle = p_mtitle.
      ld_format = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
      w_doc_data-doc_size = 1.
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = pit_attach[].
      clear t_attachment.
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = w_doc_data
          put_in_outbox              = 'X'
          sender_address             = ld_sender_address
          sender_address_type        = ld_sender_address_type
          commit_work                = 'X'
        IMPORTING
          sent_to_all                = w_sent_all
        TABLES
          packing_list               = t_packing_list
          contents_bin               = t_attachment
          contents_txt               = it_message
          receivers                  = t_receivers
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          document_type_not_exist    = 3
          operation_no_authorization = 4
          parameter_error            = 5
          x_error                    = 6
          enqueue_error              = 7
          OTHERS                     = 8.
      if sy-subrc = 0.
        commit work.
        SUBMIT rsconn01 USING SELECTION-SET 'SAP&CONNECTINT' AND RETURN.
      else.
        MESSAGE s027(vv) WITH 'E-mail not sent'.
      endif.
    Populate error return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.                    "send_attachment

    Just copy the code below and execute . I just checked and found the exact values on attachment with no blank lines. This is more simple than the one u have written , just include ur data upload logic . For ITAB values to be attached i have written a simple logic to retrive from EKPO. Just copy this code and execute. u will understand then.
    I understand that ur initial requirement was to attach the file directly and not to upload and attach. If u still want to go for the old requirement then check out the code(2nd program of the two that i have sent) that i have sent u on ur previous post.
    REPORT  ZEMAIL_ATTACH                   .
    TABLES: ekko.
    PARAMETERS: p_email   TYPE somlreci1-receiver
                                      DEFAULT '[email protected]'.
    TYPES: BEGIN OF t_ekpo,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
    END OF t_ekpo.
    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
          wa_ekpo TYPE t_ekpo.
    TYPES: BEGIN OF t_charekpo,
      ebeln(10) TYPE c,
      ebelp(5)  TYPE c,
      aedat(8)  TYPE c,
      matnr(18) TYPE c,
    END OF t_charekpo.
    DATA: wa_charekpo TYPE t_charekpo.
    DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
            t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
            t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            w_cnt TYPE i,
            w_sent_all(1) TYPE c,
            w_doc_data LIKE sodocchgi1,
            gd_error    TYPE sy-subrc,
            gd_reciever TYPE sy-subrc.
    *START_OF_SELECTION
    START-OF-SELECTION.
      Retrieve sample data from table ekpo
      PERFORM data_retrieval.
      Populate table with detaisl to be entered into .xls file
      PERFORM build_TXT_data_table.
    *END-OF-SELECTION
    END-OF-SELECTION.
    Populate message body text
      perform populate_email_message_body.
    Send file by email as .TXT speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_message
                                          it_attach
                                    using p_email
                                          'Example .TXT documnet attachment'
                                          'TXT'
                                          'filename'
                                 changing gd_error
                                          gd_reciever.
      Instructs mail send program for SAPCONNECT to send email(rsconn01)
      PERFORM initiate_mail_execute_program.
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT ebeln ebelp aedat matnr
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekpo.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  BUILD_TXT_DATA_TABLE
          Build data table for .txt document
    FORM build_txt_data_table.
      CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
                 con_tab TYPE x VALUE '09'.   "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    *constants:
       con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
       con_cret type c value cl_abap_char_utilities=>CR_LF.
      CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
             INTO it_attach  SEPARATED BY SPACE . "con_tab.
    CONCATENATE con_cret it_attach  INTO it_attach." Use this if req.
      APPEND  it_attach.
      LOOP AT it_ekpo INTO wa_charekpo.
        CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
                    wa_charekpo-aedat wa_charekpo-matnr
               INTO it_attach SEPARATED BY SPACE ."con_tab.
       CONCATENATE con_cret it_attach  INTO it_attach." Use this if req.
        APPEND  it_attach.
      ENDLOOP.
    ENDFORM.                    " BUILD_txt_DATA_TABLE
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM send_file_as_email_attachment tables pit_message
                                              pit_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = pit_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
          Instructs mail send program for SAPCONNECT to send email.
    FORM initiate_mail_execute_program.
      WAIT UP TO 2 SECONDS.
      SUBMIT rsconn01 WITH mode = 'INT'
                    WITH output = 'X'
                    AND RETURN.
    ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
    *&      Form  POPULATE_EMAIL_MESSAGE_BODY
           Populate message body text
    form populate_email_message_body.
      REFRESH it_message.
      it_message = 'Please find attached a list test ekpo records'.
      APPEND it_message.
    endform.                    " POPULATE_EMAIL_MESSAGE_BODY
    execute this code and i hope that will help u.
    regards,
    Barath.

  • How to read the second line in a .txt file with bufferedReader?

    hi,
    i am not the best in speaking english and programming java :)
    so, just try to make sense of my question:
    Im using a BufferedReader to read a .txt file.
    the .txt file has 5+ different lines, and each line has 6 tokens (separated with ; )
    My java file has 6 textFields and each textfield is filled with one of the 6 different tokens.
    and my problem is:
    I want my buffered reader to read the next line (with 6 new different tokens) by pressing a button.
    if somethings not understandable, just ask :)

    maybe its easier to help me, when i publish my code, so here it is:
    (its my version, without Thof's code. Sorry, but the comments are the most in german)
    /* userdata.java */
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class userdata extends Frame {
    //-----------------------------------KlassenVariablen------------------------------------------------
    private JPanel panel = new JPanel ();
    String tokId = "";
    String tokName= "";
    String tokAge= "";
    String tokTel= "";
    String tokMail= "";
    String tokText= "";
    BufferedReader br;
    String zeile;
    StringTokenizer st;
    String delim = ";";
    //---------Buttons f?r Panel 1-------------------------
    Button first = new Button("|< First");
    Button back = new Button("< Back");
    Button next = new Button("Next >");
    Button last = new Button("Last >|");
    //---------Buttons f?r Panel 3-------------------------
    Button neu = new Button("New");
    Button safe = new Button("Safe");
    Button refresh = new Button("Refresh");
    //--------Labels f?r Panel 2-----------------------------
    Label lid = new Label("ID",Label.LEFT);
    Label lname = new Label("Name",Label.LEFT);
    Label lage = new Label("Age",Label.LEFT);
    Label ltel = new Label("Tel.",Label.LEFT);
    Label lmail = new Label("E-Mail",Label.LEFT);
    Label ltext = new Label("Spruch",Label.LEFT);
    Label lub = new Label("Last Button",Label.LEFT);
    TextField id = new TextField();
    TextField name = new TextField();
    TextField age = new TextField();
    TextField tel = new TextField();
    TextField mail = new TextField();
    TextField text = new TextField();
    TextField usedbutton = new TextField();
    //--------ActionEvent bla sachen eben--------------------
    public static void main (String[] args) throws IOException {
    userdata wnd = new userdata();
    wnd.setVisible(true);
    public userdata() throws IOException {                                                                                                                                                                                                                                                                                
    //--------------------------------Layout mit panel bestimmung--------------------------------------
    setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();
    add(BorderLayout.NORTH ,p1);
    add(BorderLayout.CENTER , p2);
    add(BorderLayout.SOUTH , p3);
    //-------------------------------Funktionslose Buttons in PANEL 1------------------------------------
    p1.add(first);
    p1.add(back);
    p1.add(next);
    p1.add(last);
    p1.add(usedbutton);
    //--------------------------------Funktionierende Textfelder in PANEL 2------------------------------
    Panel labelpanel = new Panel();
    p2.setLayout(new GridLayout(7,3));
    p2.add(lid);
    p2.add(id);
    p2.add(lname);
    p2.add(name);
    p2.add(lage);
    p2.add(age);
    p2.add(ltel);
    p2.add(tel);
    p2.add(lmail);
    p2.add(mail);
    p2.add(ltext);
    p2.add(text);
    p2.add(lub);
    p2.add(usedbutton);
    //--------------------------------------Buttons in PANEL 3-----------------------------------------
    p3.add(neu);
    p3.add(safe);
    p3.add(refresh);
    //--------------------------------BufferedReader -------------------------------------------------
    readData();
    //--------------------------------Panel 2 TextField-----------------------------------------------
    fillForm();
    //================================ActionPerformed==================================================
    first.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("First");
    usedbutton.setText("First");
    back.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Back");
    usedbutton.setText("Back");
    next.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Next");
    usedbutton.setText("Next");
    last.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Last");
    usedbutton.setText("Last");
    neu.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("New entry");
    usedbutton.setText("New");
    safe.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Now Saving, do not turn off!");
    usedbutton.setText("Save");
    //-----------------refresh
    refresh.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    try{
    readData();
    }catch( IOException ioe){
    System.out.println("Fehler beim lesen aus Datei");
    fillForm();
    usedbutton.setText("Refresh");
    //=============================================================================Button Funktionen!!!
    pack();
    //--------------------------------WindowsListener hinzuf?gene--------------------------------------
    addWindowListener(
    new WindowAdapter() {
    public void windowClosing(WindowEvent event)
    setVisible(false);
    dispose();
    System.exit(0);
    //-----------------------------------readData() - > Buffered Reader in aktion! --------------------
    private void readData() throws IOException{
    BufferedReader br = new BufferedReader(new FileReader("My .txt File with path"));
    String zeile;
    StringTokenizer st;
    String delim = ";";
    zeile = br.readLine();
    st = new StringTokenizer(zeile, delim);
    st.hasMoreTokens();
    //System.out.println (st.nextToken());
    tokId = new String(st.nextToken());
    tokName = new String (st.nextToken());
    tokAge = new String (st.nextToken());
    tokTel = new String (st.nextToken());
    tokMail = new String (st.nextToken());
    tokText = new String (st.nextToken());
    //--------------------------fillForm() - > f?llt die TextFelder aus!--------------------------------
    private void fillForm(){
    id.setText(tokId);
    name.setText(tokName);
    age.setText(tokAge);
    tel.setText(tokTel);
    mail.setText(tokMail);
    text.setText(tokText);
    }

  • Read a specific line of a txt file using vba not using line by line, Leer una Linea especifica de archivo de texto sin recorrer linea por linea

    Buenos días - Good morning
    Mi pregunta la escribiré en español y en ingles y espero alguien tenga la solución.
    I'll write my question in Spanish and English and I hope someone has the solution.
    SPANISH
    Creé una Macro en VBA que lee mas de 200.000 archivos de texto (.txt) los cuales tienen diferentes tamaños y cantidad de información dentro de ellos, de cada archivo necesito extraer la información de las 3 primeras lineas y las ultimas 10 lineas, las 3
    primeras lineas es fácil ya que uso un "READLINE" 3 veces y voy capturando la información de las tres primeras lineas, para las ultimas 10 lineas las cuales están identificadas por un código inicial hago un ciclo que lee linea por linea hasta que
    encuentra el numero 3 en un espacio especificado de la linea y de ahí captura la información de cada linea de texto que serian las 10 ultimas, el problema que tengo es que la cantidad de archivos y de información dentro de los archivos aumenta considerablemente
    cada día y por tener el ciclo que lee cada una de las lineas de cada archivo de texto la Macro se demora cada vez mas a medida que aumenta la información y consume cada vez mas memoria de la maquina.
    Necesito un método diferente que no lea linea por linea y que yo le pueda decir lea la linea (renglón) numero 1000 (ejemplo) y capture la información a partir de ahí para ahorrar algo de tiempo, o saber cuantas lineas de texto tiene el archivo .txt y decirle
    que me lea a partir de (numero total de lineas del txt -(menos) 10 lineas) así me leería las 10 ultimas.
    ENGLISH
    I created a Macro in VBA that reads more than 200,000 text files (.txt) which have different sizes and quantity of information within them, each file need to extract the information from the first 3 lines and last 10 lines, 3 first lines is easy as using a
    'READLINE "3 times and am capturing information from the first three lines, for the last 10 lines which are identified by an initial code I make a loop that reads line by line until it finds the number 3 in a specified area of ​​the line and then capture
    the information of each line of text that would be 10 last, the problem that I have is that the number of files and information within files significantly increases every day and having the loop that reads each line of each text file is delayed Macro increasingly
    as more information and consume more and more memory on the machine.
    I Need a different method not read line by line and I can tell you read the line (row) number 1000 (example) and capture the information from there to save some time or know how many lines of text have the file .txt and tell me read from (total number of lines
    of txt - (minus) 10 lines) so I would read 10 last.
    Here is the code I currently use
    Dejo el código que uso actualmente
    Dim fs, f, ts, REG
    Set fso = CreateObject("Scripting.FileSystemObject")
        On Error Resume Next
    sFilePath = strFolder & "\" & strFileName
    Set f = fso.getFile(sFilePath)
    Set ts = f.OpenAsTextStream(1, 0)
    REG = ts.READLINE
    Ciclo para llegar hasta las ultimas 10 lineas
    Cycle to reach the last 10 lines
    For J = 1 To 200000
                REG = ts.READLINE
                    If Val(Mid(REG, 6, 1)) = 3 Then

    Good Morning ryguy72
    First thank you so much for your answer, sorry for my english in the question, I tried for a long time to make a code that wasn't so slow to read the last 10 lines, 'cuz most codes used a cycle "For" to read line by line asking if in the specific
    position is the character(number) that tells me that i should get started to read the last lines that i need, that takes a lot longer than your code doing a Split with Mydata and storing it in strData(). I don't know how to do this and every forum that
    i consulted to read the last 10 lines quickly they made the same read line by line with a Cycle "for".
    Thanks again, I gonna improve my code with your help, 'cuz it took about 4 hours to read all the information and everyday ascended more time and memory consumption.
    Thanks to everyone who offered their help so disinterested and free, so should always be people with that spirit, I hope someday to be SO good as you programming.

  • Need existing custom script to run with a .csv or .txt file

    Hi, Scripting Guys!
    I am a very novice novice when it comes to PowerShell -- I'll state that up front. So apologies if the answer to this is really basic. I am trying to use a script written by someone else, where I can simply paste in the script, identify the user by any one
    of several attributes, and the magic happens (in this case, all mail attributes in the AD Object are cleared and then the email address is added back in, resetting that object to the point where IDSync can run).  For a single user at a time, it works
    perfectly.
    .\Reset-MailAccountforIDSync.ps1 -Identity "[email protected]"
    My problem is that I have a .csv file with 60 users I need to run this script on, and there's a possibility of other large batches in the future.  How can I convert this single user script into one that can work with a .csv or .txt file?
    Thanks, Stormicat/J.L.Newmark

    This will do the trick.
    $csv=Import-Csv users.csv
    foreach($user in $csv){
    .\Reset-MailAccountforIDSync.ps1 -Identity $user.Mail
    Of course you will have to learn enough to understand that so start here:
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    ¯\_(ツ)_/¯

  • Append a top line to multiple txt files

    Hi there,
    I have to manipulate txt files in powershell and I may not be very good at it... so any help is welcome ^^
    I've got multiple files in a single folder. They are exports from a DB and are formatted like that :
    "name1"
    "name2"
    "name3"
    I need them to be :
    =1
    name1
    name2
    name3
    In short I have to remove all the quotes and add "=1" on the first line of each file.
    Here's what I've got so far :
    $fileEntries = [IO.Directory]::GetFiles("C:\temp");
    foreach($fileName in $fileEntries)
    (Get-Content $fileName) |
    Foreach-Object {$_ -replace '"', "" } |
    Set-Content $fileName
    foreach($fileName in $fileEntries)
    Write-Output "=1`n" | Out-File $fileName -Append
    It appends at the last line, I just can't get the "=1" at the top... any help would be much appreciated !
    Thanks !

    Hi,
    This will do what you're after:
    Get-ChildItem C:\Temp -File | ForEach {
    $stripped = (Get-Content $_.FullName).Replace('"','')
    Write-Output '=1' | Out-File $_.FullName
    $stripped | Out-File $_.FullName -Append
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)

Maybe you are looking for