Discard lines from File

Dear All,
I have an inbound file to PI.
In the file, there are few lines which are not to be used ... those appear in the top, bottom as well as somewhere in the middle of the file.
I know how to take care of undesired lines from the top, but how to take care of those coming in the middle and the bottom? The number of rows for these undesired extra lines in top, middle and bottom of the file will always be fixed.
Example:-
TOP_LINE1               (Extra line)
TOP_LINE2               (Extra line)
DATA_LINE1
MID_LINE1               (Extra line - HELP required)
MID_LINE2               (Extra line - HELP required)
DATA_LINE1
BOTTOM_LINE1               (Extra line - HELP required)
BOTTOM_LINE2               (Extra line - HELP required)
BOTTOM_LINE3               (Extra line - HELP required)
As I mentioned earlier, the number of rows for these extra lines will always be fixed.
Any suggestions / help will be highly appreciated.
Thanks,
--Abhi

Thanks Michal for your reply.
But my scenario is a little complex. I will explain here.
1. The file is having data for CONSUMERS and PROVIDERS.
2. After the top_line undesired rows, is the section for the CONSUMERS.
3. After the mid_line undesired rows, is the section for the PROVIDERS.
4. In the file CC, if I specify RECORDSET STRUCTURE - CONSUMERS,,PROVIDERS, - it complains for keyfieldname.
What am I supposed to put in keyfieldname? I don't have any ...
A sample of the inbound file:-
,,,,,"Division",,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,Inventory Report,,,,,,,,,,,,,,,,,,,,,,,,,
Consumer Owner : ABC    ,,,,
Consumer :,,,,
Name,Contact,ID,Addr1,Addr2
John White,203 111 2222,1234,,
J D Edwards, 732 020 1121,South West Drive,NJ
Number of Consumers : 201,,,,
Providers :,,,,
ProviderName,Location,LicenseNumber,Contact
ABC,NJ,1001,1800 000 0001
DEF,NY,1005,1 888 000 0001
Number of Providers : 102,,,,
,Summary,,,
I just need the data from the bold rows. Rest of the rows should be discarded. I have desinged the structure like this -
<MT>
<rec>
<Consumer><Name> ... </Consumer>
<Provider><ProviderName>...</Provider>
</rec>
</MT>
Hope the requirement is clear. Kindly help.
Thanks a lot,
--Abhi

Similar Messages

  • I want to read lines from file, count it and extract numbers from a first line.

    i must do un loop?

    HI,
    i try to explain how to use to LABVIEW TOOLS...
    1. USE a for next loop
    2. here you must open the file with the VI. read lines from file.
    you can choos how many lines you read at same time.
    3. the string you can convert into an number.
    4. in the loop is the literal counter... this is you line couter....
    iun schrieb:
    > i must do un loop?

  • [Solved] Shell script to read unhashed lines from file.

    Hello.
    I want to write a shell script  (it can be bash,sh,ksh,csh or zsh) that will be:
    1.Read unhashed lines from file named mirrors.conf.
    2.Put them in ~/.profile as PKG_PATH=line catted from mirrors.conf.
    Just like as mirrors.conf file for pacman.
    Now it can cat lines but how to put them in files as PKG_PATH?
    Thanks for answers.
    Last edited by SpeedVin (2010-03-01 17:33:20)

    res wrote:
    ^ IFS is not necessary here; it won't mess with the white space:
    $ echo 'args with formatted spaces ' | while read -r; do echo "$REPLY"; done
    args with formatted spaces
    It matters for leading/trailing whitespace:
    $ echo ' after some ' | while read -r line; do echo "<$line>"; done
    <after some>
    $ echo ' after some ' | while IFS= read -r line; do echo "<$line>"; done
    < after some >

  • Assigning a number value to a line from file without array

    How do you assign a number value to a line from a file? I want to use the assigned number so that the i can use random number to randomly select a line
    Example. i have the lines A,B,C,D,E
    A
    B
    C
    D
    E
    i know that a is line 1 b is line 2 so on so on
    (1) A
    (2)B
    (3)C
    (4)D
    (5)E
    so from here i would use the random number generator so that i could randomly select one of these. I already know how to code for the number generator but how would i make it so that i can access each individual line as a number?

    ya that's what im using but reguarding the code i dont think it does what im looking for. yes it does provide a random line but wen i run it multiple times it gives me the same line repeatedly. also i need to be able to refer to that line in the future so in the code the String line gets replaced each time
    BufferedReader bF = new BufferedReader(new FileReader("someFilePath"));
              String line;
              int someRandomNumber = 9;
              int counter = 0;
              while ((line = bF.readLine()) != null){
                   if (counter == someRandomNumber){
                        break;
                   counter++;          
              System.out.println(line); //line at #someRandomNumber in the file

  • Delete X number of lines from files

    I am trying to find a way (either through an extension or
    some other third-party freeware) to remove a number of lines from
    the beginning of my files and replace them with alternate code.
    I know that in many cases, a Search and Replace would do the
    trick. But in my case, the lines that I want replaced do not
    exactly match. For example, I might want to remove the first 15
    lines from the beginning of each file in question; however, I might
    have three lines of code in the files that each set a variable
    value, with that value being different in each file. Thus, as far
    as I understand it, the DW Search and Replace would not work for
    me.
    Even if I have can just find some way to first strip the
    lines of code out without replacing it with the new code I want,
    that would be fine. Adding in the new code afterwards would not be
    an issue.
    Any help would be very much appreciated. Thank you very much.
    James

    On Mon, 7 May 2007 17:14:52 +0000 (UTC), "MUSC Webmaster"
    <[email protected]> wrote:
    > Gary: Thanks for the suggestion; however it wasn't quite
    working for me.
    >After your posting, I played around for a bit with
    regular expressions and the
    >best that I could do was get an expression (^.*\r) that
    grabbed all of the
    >first line, with the "r" representing a carriage return
    as opposed to a line
    >feed. If I try to expand on that expression, the search
    results come up with
    >nothing.
    Actually the linfeed is the \n in my suggestion. The ^
    designates the
    beginning of the string.
    Are you on a Mac? I tested it and it worked correctly on my
    windows
    machine. Come to think of it, I have my line feeds set to
    Unix because
    that's what my web server uses. You can try replacing the \n
    with \r or
    \n\r depending on which line feed you're using:
    ^.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r.*\r
    or:
    ^.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\ n
    One of the three should work.
    Gary

  • Delete some lines from file...

    Hi,
    I'm using this code
          File file = new File(sFile);
          if (!file.exists())
            file.createNewFile();
          fout = new PrintWriter(new OutputStreamWriter(new FileOutputStream(sFile , true)) , true);
    PrintWriter fout;
    ...When file has more then (let's write) 1000 lines, I want to delete last 100 from file.
    Can someone help me to do that? Can you posto me a part of code which will done that?
    Thanks.

    If you want to use "standard" (serial) IO, which reads from the beginning of the file, create a line counter, read the file line-by-line, and when the file size limil is reached, close the file - remaining lines will be truncated from the file.
    If the file lines are all equal in length, then you can use the RandomAccessFile methods to directly seek to the desired line and delete lines after that point using the class methods - see the seek and setLength methods.

  • Read lines from file

    Hi. I use buffered reader to read from a file. The file contains a line of strings (04/21/2005 some text bla bla here). Each line ends with a \n, to define that its the end of the line. How can i print this out, so each line is printed on a new line? Suggestions?
    String filename = "someFile.txt";
    BufferedReader infile = new BufferedReader(new FileReader(filename));
    String read;
    while ((read = infile.readLine()) != null)
         //print each line, but how?
    infile.close();

    I was wondering if the \n defines that its "end of
    line" so that all strings between the \n is
    understood as one line.Yes. It may also be \r\n, depending on the platform. It's one of the System properties. line.delimiter, I think.
    Allso, when i print with
    System.out.println(infile); only
    java.io.BufferedReader@691177 is printed. Do I have
    to parse it in any way?No. You normally can't "print" an object. All you'll do is print out the result of the object's toString() method, which usually returns the class name and the object's hash code.
    And you should keep in mind that a File object is only a representation of the file's name. It has no access to the file's contents.

  • Fire an event automatically after reading line from file

    Hi all
    I am writing a programe in which i need to fire an event automatically after reading each line (i.e. on every EOL) from the file.
    Thanks
    jon

    jonhill wrote:
    ..I am writing a programe in which i need to fire an event automatically after reading each line (i.e. on every EOL) from the file.Thanks for sharing that with us. Let us know how it goes. If you have any questions, feel free to ask them.
    BTW - sounds like a very weird requirement.

  • Read lines from text file to java prog

    how can I read lines from input file to java prog ?
    I need to read from input text file, line after line
    10x !

    If you search in THIS forum with e.g. read lines from file, you will find answers like this one:
    Hi ! This is the answer for your query. This program prints as the output itself reading line by line.......
    import java.io.*;
    public class readfromfile
    public static void main(String a[])
    if you search in THIS forum, with e.g. read lines from text file
    try{
    BufferedReader br = new BufferedReader(new FileReader(new File("readfromfile.java")));
    while(br.readLine() != null)
    System.out.println(" line read :"+br.readLine());
    }catch(Exception e)
    e.printStackTrace();
    }

  • Deleting first line off file

    Hello,
    I want to remove the first line of a file. Is there any way to do that
    without reading the whole file and putting it in a huge string?
    Something like setting the "begining of file marker" (does that
    exist?). I've looked in the "advanced file function" and can't find a
    way to do it.
    Any suggestion?
    Thanks a lot!!
    Vincent

    I don't see any Read File by Lines vi in LV7.1.  Maybe it exists in LV 8.  However there is a Read Lines from File vi but it does not produce an array of lines (at least not in LV 7.1).  You can use the Read Lines from File vi and set the number of lines to 1.  The output mark after read is now set to point to the second line.  You can use this as an input to start of read offset on your next read call.  This vi will open the file, read, then close the file.  Calling it a second time will open the file again, read, then close again.
    Another way is to open the file using Open/Create/Replace File.  Then use Read File and set the Line Mode input to True.  This will read the first line.  A second Read File call will then begin reading at the second line without having to wire any offsets.  After reading all that you want, you close the file.  One open, several reads, one close.  This is more efficient.
    Message Edited by tbob on 03-06-2007 03:03 PM
    - tbob
    Inventor of the WORM Global
    Attachments:
    ReadLines.png ‏4 KB

  • How to read last line from a .txt file?

    Hello
    I have a string: e.g. "my name is John"
    and i wanna verify if this string is equal with the last line from a text file
    for example, if in the txt file i have:
    asdasd
    sdgsdfgasd
    asdfgadfgadf
    sdgasdgsdf
    my name is john
    then it's OK.
    but if i have
    asdgsdfg
    dsfhsdfhsd
    sdgasdfg
    sdgsdg
    my name is Jdfgsdg
    this is not correct
    How should i do this?
    Thanks:)

    Read from the beginning an discard all lines (if you have a small file), or use RandomAccessFile and scan from the end till you find the beginning of the last line.
    Kaj

  • Reading a Random Line from a Text File

    Hello,
    I have a program that reads from a text file words. I currently have a text file around 800KB of words. The problem is, if I try to load this into an arraylist so I can use it in my application, it takes wayy long to load. I was wondering if there was a way to just read a random line from the text file.
    Here is my code, and the text file that the program reads from is called 'wordFile'
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class WordColor extends JFrame{
         public WordColor(){
              super("WordColor");
              setSize(1000,500);
              setVisible(true);
              add(new WordPanel());
         public static void main(String[]r){
              JFrame f = new WordColor();
    class WordPanel extends JPanel implements KeyListener{
         private Graphics2D pane;
         private Image img;
         private char[]characterList;
         private CharacterPosition[]positions;
         private int charcounter = 0;
         private String initialWord;
         private File wordFile = new File("C:\\Documents and Settings\\My Documents\\Java\\projects\\WordColorWords.txt");
         private FontMetrics fm;
         private javax.swing.Timer timer;
         public final static int START = 20;
         public final static int delay = 10;
         public final static int BOTTOMLINE = 375;
         public final static int buffer = 15;
         public final static int distance = 4;
         public final static Color[] colors = new Color[]{Color.red,Color.blue,Color.green,Color.yellow,Color.cyan,
                                                                          Color.magenta,Color.orange,Color.pink};
         public static String[] words;
         public static int descent;
         public static int YAXIS = 75;
         public static int SIZE = 72;
         public WordPanel(){
              words = readWords();
              setLayout(new BorderLayout());
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              setFocusable(true);
              addKeyListener(this);
              timer = new javax.swing.Timer(delay,new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        YAXIS += 1;
                        drawWords();
                        if (YAXIS + descent - buffer >= BOTTOMLINE) lose();
                        if (allColorsOn()) win();
         public void paintComponent(Graphics g){
              super.paintComponent(g);
              if (img == null){
                   img = createImage(getWidth(),getHeight());
                   pane = (Graphics2D)img.getGraphics();
                   pane.setColor(Color.white);
                   pane.fillRect(0,0,getWidth(),getHeight());
                   pane.setFont(new Font("Arial",Font.BOLD,SIZE));
                   pane.setColor(Color.black);
                   drawThickLine(pane,getWidth(),5);
                   fm = g.getFontMetrics(new Font("Arial",Font.BOLD,SIZE));
                   descent = fm.getDescent();
                   distributePositions();
                   drawWords();
                   timer.start();
              g.drawImage(img,0,0,this);
         private void distributePositions(){
              int xaxis = START;
              positions = new CharacterPosition[characterList.length];
              int counter = 0;
              for (char c: characterList){
                   CharacterPosition cp = new CharacterPosition(c,xaxis, Color.black);
                   positions[counter] = cp;
                   counter++;
                   xaxis += fm.charWidth(c)+distance;
         private void drawThickLine(Graphics2D pane, int width, int thickness){
              pane.setColor(Color.black);
              for (int j = BOTTOMLINE;j<BOTTOMLINE+1+thickness;j++){
                   pane.drawLine(0,j,width,j);
         private void drawWords(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              drawThickLine(pane,getWidth(),5);
              for (CharacterPosition cp: positions){
                   int x = cp.getX();
                   char print = cp.getChar();
                   pane.setColor(cp.getColor());
                   pane.drawString(""+print,x,YAXIS);
              repaint();
         private boolean allColorsOn(){
              for (CharacterPosition cp: positions){
                   if (cp.getColor() == Color.black) return false;
              return true;
         private Color randomColor(){
              int rand = (int)(Math.random()*colors.length);
              return colors[rand];
         private void restart(){
              charcounter = 0;
              for (CharacterPosition cp: positions){
                   cp.setColor(Color.black);
         private void win(){
              timer.stop();
              newWord();
         private void newWord(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              repaint();
              drawThickLine(pane,getWidth(),5);
              YAXIS = 75;
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              distributePositions();
              charcounter = 0;
              drawWords();
              timer.start();
         private void lose(){
              timer.stop();
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              pane.setColor(Color.red);
              pane.drawString("Sorry, You Lose!",50,150);
              repaint();
              removeKeyListener(this);
              final JPanel p1 = new JPanel();
              JButton again = new JButton("Play Again?");
              p1.add(again);
              add(p1,"South");
              p1.setBackground(Color.white);
              validate();
              again.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        remove(p1);
                        addKeyListener(WordPanel.this);
                        newWord();
         private String getWord(){
              int rand = (int)(Math.random()*words.length);
              return words[rand];
         private String[] readWords(){
              ArrayList<String> arr = new ArrayList<String>();
              try{
                   BufferedReader buff = new BufferedReader(new FileReader(wordFile));
                   try{
                        String line = null;
                        while (( line = buff.readLine()) != null){
                             line = line.toUpperCase();
                             arr.add(line);
                   finally{
                        buff.close();
              catch(Exception e){e.printStackTrace();}
              Object[] objects = arr.toArray();
              String[] words = new String[objects.length];
              int count = 0;
              for (Object o: objects){
                   words[count] = (String)o;
                   count++;
              return words;
         public void keyPressed(KeyEvent evt){
              char tempchar = evt.getKeyChar();
              String character = ""+tempchar;
              if (character.equalsIgnoreCase(""+positions[charcounter].getChar())){
                   positions[charcounter].setColor(randomColor());
                   charcounter++;
              else if (evt.isShiftDown()){
                   evt.consume();
              else{
                   restart();
              drawWords();
         public void keyTyped(KeyEvent evt){}
         public void keyReleased(KeyEvent evt){}
    class CharacterPosition{
         private int xaxis;
         private char character;
         private Color color;
         public CharacterPosition(char c, int x, Color col){
              xaxis = x;
              character = c;
              color = col;
         public int getX(){
              return xaxis;
         public char getChar(){
              return character;
         public Color getColor(){
              return color;
         public void setColor(Color c){
              color = c;
    }

    I thought that maybe serializing the ArrayList might be faster than creating the ArrayList by iterating over each line in the text file. But alas, I was wrong. Here's my code anyway:
    class WordList extends ArrayList<String>{
      long updated;
    WordList readWordList(File file) throws Exception{
      WordList list = new WordList();
      BufferedReader in = new BufferedReader(new FileReader(file));
      String line = null;
      while ((line = in.readLine()) != null){
        list.add(line);
      in.close();
      list.updated = file.lastModified();
      return list;
    WordList wordList;
    File datFile = new File("words.dat");
    File txtFile = new File("input.txt");
    if (datFile.exists()){
      ObjectInputStream input = new ObjectInputStream(new FileInputStream(datFile));
      wordList = (WordList)input.readObject();
      if (wordList.updated < txtFile.lastModified()){
        //if the text file has been updated, re-read it
        wordList = readWordList(txtFile);
        ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
        output.writeObject(wordList);
        output.close();
    } else {
      //serialized list does not exist--create it
      wordList = readWordList(txtFile);
      ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
      output.writeObject(wordList);
      output.close();
    }The text file contained one random sequence of letters per line. For example:
    hwnuu
    nhpgaucah
    zfbylzt
    hwnc
    gicgwkhStats:
    Text file size: 892K
    Serialized file size: 1.1MB
    Time to read from text file: 795ms
    Time to read from serialized file: 1216ms

  • How to delete string or line from unix file(dataset) of application server

    Hi  All,
    After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
    I have tried for single record than also the file generates the last line(2nd line) also a blank line.
    When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
    How to delete string or line from unix file(dataset) of application server?
    Please give your comments to resolve this.
    Thanks
    Tirumula Rao Chinni

    Hi Rio,
    I faced similar kind of issue working with files on UNIX platform.
    The line is a line feed to remove it use
    DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf. 
      DATA : lv_carr_return TYPE char1,                                   
             lv_line_feed   TYPE char1.                                          
      lv_line_feed   = lv_carr_linefd(1).
      lv_carr_return = lv_carr_linefd+1(1).
    Note: IMP: The character in ' ' is not space but is a special
    character set by pressing ALT and +255 simultaneosly
      REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
      REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '.

  • Delete lines from a text file

    i need to delete (or replace them with white space) a few lines from a text file. I have a text file with first few lines & last few lines containing "<"or ">". I need to delete/replace with white space, the entire line. i need to do this urgently
    Could some one please tell me how to do this?

    the file can be of size 8MB or more. i get this file
    every week from a third party. So the size is not
    constant. I need to remove/replace with white space,
    the fist & last few lines and the rest is comma
    seperated values which i need to load to database
    using sqlldr. But still not sure abt how to remove
    the first few lines.
    i need to read this file, replace the lines as i read
    them and write the replaced string back to the file &
    then load the rest of lines to database.8 MByte is fairly small. Read the file a line at a time and copy to a new file only the lines you want. Should take no more than a second or so.
    P.S. It will probably be a mistake if you try to edit the original file in place.

  • How to upload  schedule line from flat files to sap file

    dear all,
    i want to upload the schedule lines from flat files to sap schedulle lines
    but the flat files have 15 schedule lines and the data is as per date
    so how to upload that and the fields available in flat files are more than the sap screen
    we are having more than 6 items
    and 15scedule lines its abt 90data to be upload
    for one customer in every 15 day
    so how to do this
    is there any direct use in functional side
    with out the help of any abap
    but my user will do it
    so he need a permanent solution
    with regards
    subrat

    Hi Subrat ,
    u can upload the data either ( Master /Transaction) data with the help of lsmw. for that all u need to do is go through the lsmw and do it. in that u can go Batch input recording/ BAPI/ IDOC any of that. here i am sending the LSMW Notes go through it and do the work.
    once u create the LSMW project then u can ask the data from user or u can explain the user about the program and can run the flat file to upload the data.
    if u require LSMW material Just send me blank mail from u. my mail id is [email protected]
    Reward if Helpful.
    Regards,
    Praveen Kumar.D

Maybe you are looking for

  • Where do I forward an e-mail message that say it's from Apple, but appears to be a phishing scam?

    I received an email with a reply address of [email protected] Here is the body of the message: "As we strive to secure your account, please be informed to upgrade to our latest security platform ***** Your privacy and protection is our concern. Apple

  • Exporting specific tracks

    I just downloaded Sound Studio and was trying to find a way to get individual recorded tracks from a GarageBand song into Sound Studio to edit them. Is there even a way to take specific tracks out of a GarageBand song?

  • To fetch data using group by function

    Hi Guys, I am having a table where it holds data with value with zero in one of the column and i need to fetch the records from the table using group by function but to display all the records if zero occurs in my table for eg table1 id,customer_name

  • Lightroom 2.1 - 32-bit vs 64-bit performance tests

    Hey all...I posted quite a while back about Lightroom 2.0's 64-bit performance issues. Anyway, I just posted some updated tests of Lightroom 2.1, running in both 32- and 64-bit modes; I was very pleasantly surprised by the great 64-bit performance. H

  • Find date and Time for a record.

    Is there any way to find out when any record in table was created? Thx