Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Extract data and display values - Help

    Greetings to all.

    Hope someone can help me.

    I need a particular set of lines extracted and displayed. Below are the details.

    From these set of lines (I want the BOLD content as an extracted one and stored) - ScripsContent.txt contains the below content and is attached:
    20MICRONS
    EXCHANGE%3DNSE
    MARKET_OPEN_MINUTE=555
    MARKET_CLOSE_MINUTE=930
    INTERVAL=1800
    COLUMNS=DATE,CLOSE
    DATA=
    TIMEZONE_OFFSET=330
    a1468987200,28.6
    1,28.35
    2,28.5
    3,28.5
    4,28
    5,28.4
    6,28.45
    7,28.3

    3IINFOTECH
    EXCHANGE%3DNSE
    MARKET_OPEN_MINUTE=555
    MARKET_CLOSE_MINUTE=930
    INTERVAL=1800
    COLUMNS=DATE,CLOSE
    DATA=
    TIMEZONE_OFFSET=330
    a1468987200,5.05
    1,5
    2,5.05
    3,5.05
    4,5.05
    5,5.05
    6,5.05
    7,5.05

    3MINDIA
    EXCHANGE%3DNSE
    MARKET_OPEN_MINUTE=555
    MARKET_CLOSE_MINUTE=930
    INTERVAL=1800
    COLUMNS=DATE,CLOSE
    DATA=
    TIMEZONE_OFFSET=330
    a1468987200,13500
    1,13,450.65
    2,13,350
    3,13,449.95
    4,13,450
    5,13,460
    6,13,469.95
    7,13,482.25


    Code snippet:
    Java Code:
    package test;
    
    import java.io.*;
    import java.net.URL;
    
    public class Test_1 {
    	public static void main(String[] args) throws IOException {
    		BufferedReader br = new BufferedReader(new FileReader(
    				"C://Users//Cheers//Desktop//ScripsList.txt"));
    		String strLine, queue_url;
    		try {
    
    			FileWriter fw = new FileWriter(
    					"C://Users//Cheers//Desktop//ScripsContent.txt");
    			PrintWriter out = new PrintWriter(fw);
    
    			while ((strLine = br.readLine()) != null) {
    
    				queue_url = "http://www.google.com/finance/getprices?q="
    						+ strLine + "&x=NSE&i=1800&p=1d&f=d,c";
    
    				out.println(strLine);
    				
    				URL oracle = new URL(queue_url);
    				BufferedReader in = new BufferedReader(new InputStreamReader(
    						oracle.openStream()));
    
    				String inputLine;
    				while ((inputLine = in.readLine()) != null)
    					out.println(inputLine);
    				in.close();
    			}
    			out.flush();
    			out.close();
    			fw.close();
    
    			System.out.println("Job done");
    
    		} catch (IOException x) {
    			System.err.println(x);
    		} finally {
    			if (br != null)
    				br.close();
    		}
    
    	}
    }
    Thanks in-advance.
    Attached Files Attached Files
    Last edited by leslieprabakar; 07-20-2016 at 10:20 AM. Reason: File name rightly updated in the code

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Extract data and display values - Help

    The simplest way is to check the input line if it starts with a word you don't want:
    Java Code:
    List<String> ignore = new ArrayList<>();
    ignore.add("EXCHANGE");
    ignore.add("MARKET_OPEN_MINUTE");
    //etc
    
    for ( String ig : ignore) {
       if( inputLine.startsWith(ig)) {
          continue;
       }
    }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Re: Extract data and display values - Help

    Thanks dear SurfMan.

    But unfortunately I really do not know how to run the complete code as I get error like below:
    Multiple markers at this line
    - Syntax error on tokens, delete these tokens
    - Line breakpoint:Test_1 [line: 42] - main(String[])

    Extract data and display values - Help-err.png

    Quote Originally Posted by SurfMan View Post
    The simplest way is to check the input line if it starts with a word you don't want:
    Java Code:
    List<String> ignore = new ArrayList<>();
    ignore.add("EXCHANGE");
    ignore.add("MARKET_OPEN_MINUTE");
    //etc
    
    for ( String ig : ignore) {
       if( inputLine.startsWith(ig)) {
          continue;
       }
    }

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Extract data and display values - Help

    I never said I'd give you a copy/paste answer.

    First of all, that list needs to be created only once, at the beginning of your application.

    And come to think of it, the continue now skips for the for-loop instead of the while-loop. (My bad...) You should probably move the check to a separate method:
    Java Code:
    while ((inputLine = in.readLine()) != null)
        if( containsBadWord( inputLine)) {
           continue;
        }
        ///use the line here
    }
    
    private boolean containsBadWord(String inputLine) {
       for ( String ig : ignore) {
          if( inputLine.startsWith(ig)) {
              return true;
          }
       }
       return false;
    }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Re: Extract data and display values - Help

    Thanks SurfMan for the reply. Done a good job. You made my thoughts simply come true.

  6. #6
    Join Date
    Jul 2016
    Posts
    4
    Rep Power
    0

    Default Re: Extract data and display values - Help

    There is a small help needed on arrangement of the content.

    I could not transpose values with the following Java code, and in need of properly arranged table. Extract data and display values - Help-expected-output.png

    Can someone kindly help please.

    Small code change happened in Java file:
    Java Code:
    package test;
    
    import java.io.*;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Test_1 {
    	public static void main(String[] args) throws IOException {
    		BufferedReader br = new BufferedReader(new FileReader(
    				"C://Users//Cheers//Desktop//ScripsList.txt"));
    		String strLine, queue_url;
    		try {
    
    			FileWriter fw = new FileWriter(
    					"C://Users//Cheers//Desktop//ScripsDetails.csv");
    			PrintWriter out = new PrintWriter(fw);
    
    			while ((strLine = br.readLine()) != null) {
    				queue_url = "http://www.google.com/finance/getprices?q="
    						+ strLine + "&x=NSE&i=1800&p=1d&f=d,c";
    
    				out.print(strLine + "\t");
    				System.out.println(strLine);
    
    				URL oracle = new URL(queue_url);
    				BufferedReader in = new BufferedReader(new InputStreamReader(
    						oracle.openStream()));
    
    				String inputLine;
    				while ((inputLine = in.readLine()) != null) {
    					if (containsBadWord(inputLine)) {
    						continue;
    					}
    					out.print("\t "+inputLine);
    					System.out.println(inputLine.toString());
    				}
    				in.close();
    				out.println();
    			}
    			out.flush();
    			out.close();
    			fw.close();
    
    			System.out.println("Job done");
    
    		} catch (IOException x) {
    			System.err.println(x);
    		} finally {
    			if (br != null)
    				br.close();
    		}
    
    	}
    
    	private static boolean containsBadWord(String inputLine) {
    
    		List<String> ignore = new ArrayList<>();
    		ignore.add("EXCHANGE%3D");
    		ignore.add("MARKET_OPEN_MINUTE");
    		ignore.add("MARKET_CLOSE_MINUTE");
    		ignore.add("INTERVAL=");
    		ignore.add("COLUMNS=");
    		ignore.add("DATA=");
    		ignore.add("TIMEZONE_OFFSET=");
    
    		/*
    		 * ignore.add("EXCHANGE%3DNSE"); ignore.add("MARKET_OPEN_MINUTE=555");
    		 * ignore.add("MARKET_CLOSE_MINUTE=930"); ignore.add("INTERVAL=1800");
    		 * ignore.add("COLUMNS=DATE,CLOSE"); ignore.add("DATA=");
    		 * ignore.add("TIMEZONE_OFFSET=330");
    		 */
    
    		for (String ig : ignore) {
    			if (inputLine.startsWith(ig)) {
    				return true;
    			}
    		}
    		return false;
    	}
    }
    Last edited by Norm; 07-20-2016 at 07:53 PM. Reason: Changed code tags to use [] vs <>

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Extract data and display values - Help

    You're dumping the inputline straight into the file. If you're not happy with the way the inputLine looks, you should not just dump it in the file. Instead, parse it and break it down into the chunks that you want. And only write that to the file.

    Start by printing out the raw inputLine to System.out and take a good look at how they are structured. Then depending on the format, you could use either split it on tokens like a space or a tab, or use a Regex to parse the line (you now have two problems).
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Extract HashMap values to make a TreeSet
    By lannie1980 in forum New To Java
    Replies: 14
    Last Post: 04-25-2012, 10:04 PM
  2. How extract data from image file
    By Balasubrahmanyam in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-27-2011, 07:01 AM
  3. use of ajax and jsp to extract values from a table
    By sandy1000 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-27-2010, 11:26 AM
  4. how to extract cmyk values in a pdf file
    By jkrishnanvenkat in forum New To Java
    Replies: 0
    Last Post: 01-22-2010, 02:02 PM
  5. Java Extract PDF data from location XY
    By Unite in forum Advanced Java
    Replies: 1
    Last Post: 06-30-2008, 01:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •