How to find a string in a text file

i'll have a text file in the following format and from this this type of file i've to get source URL i.e in the following file http://www.consolidatorshopper.com/patheo/Mall/prices.asp
and also i've to get POSTdata querystring i.e in the following file from cosolidateorname...... to &conid6=7
hope you people understood my problem
i'll be very thankful if u people help me
BEGIN HEADER
source:http://www.consolidatorshopper.com/patheo/Mall/prices.asp
POSTdata:consolidatorname=IF&AgentID=37344&SubAgentID=31030&LoginType=SUBAGNT&LoginConfirm=yes&ManageAccount=&CustomAccount=6&PALPowerSearch=2&ShowConsolidatorsOnPricesPage=0&PALHomePage=http://www.consolidatorshopper.com&PMarkup=0&PALLoginText=<B>Specific%20Consolidator%20Search:</B><BR>%20Click%20on%20the%20desired%20region%20on%20the%20map.<BR><BR><B>Power%20Search:</B><BR>To%20search%20all%20consolidators%20simultaneously%20click%20on%20the%20button%20below.%20However,%20not%20all%20consolidators%20currently%20participate%20in%20the%20Power%20Search.&PALrelativeLoginURL=&PALrelativeBookingURL=&[email protected]&SiteID=3&MallOwnerMarkupFlat=&conidselected=16&powersearch=2&iscontinentselected=1&Continent=USDomestic&Source=1&CRSName=AP&[email protected]&ConsolidatorURL=http://www.patheo.com&ConsolidatorPhone=714-677-0929&ConsolidatorFax=714-908-7110&ConsolidatorFullName=Patheo&noofconselected=7&amadeusconidstring=&flagamadeus=1&PowerSearchConsolidatorstring=&PublishedCRS=&APPseudoCity=&SBPseudoCity=&AMLogin=&AMPassword=&AMCorpID=&AMCatNo=&ConsolidatorFares=1&PublishedFares=0&PublishedConsolidator=0&PreferencedConsolidator=&Arciata=&dep_from=MIA&dep_to=LON&ret_from=LON&ret_to=MIA&dep_month=08&dep_day=08&dep_year=2003&dep_weekday=Thu&txtLengthOfStay=7&ret_month=08&ret_day=15&ret_year=2003&ret_weekday=Thu&dep_time=12P&ret_time=12P&triptype=RoundTrip&simpleclass=Economy&srchAirline=&adultno=1&childno=0&infantno=0&conid0=11&conid1=97&conid2=1&conid3=86&conid4=5&conid5=94&conid6=7
BEGIN INFORMATION
TimeStamp:datetime:date()
BEGIN ACTION
startafter:<tr valign=middle bordercolor=#ffffff>endat:</table>
pattern:<font face='Arial, Helvetica, sans-serif' size='2'>[^<]*
$1:SYMBOL:TEXT
$2:INDEX:TEXT
$3:CLOSING:FLOAT
$4:CHANGE:FLOAT:StripHTMLTags()
$5:CHANGEPCT:FLOAT:StripHTMLTags()
BEGIN DO

Hi, this is my fourth post to forum.java.sun.com and my final one for the day, so I can allow feedback to emerge on my compliance or lack thereof with the conventions of the board.
Fortunately, I have picked up the skill of telepathy and so am able to answer your question. :)
In your processLine(String line) method or equivalent, you can do something like this:
if (line.indexOf("source:") == 0) {
   source = line.substring(6, line.length());
} else if (line.indexOf("POSTdata:") == 0) {
   postdata = line.substring(9, line.length());

Similar Messages

  • How to search a String within a text file ?

    ************** text file ****************
    Good bye good
    bye good bye
    good bye
    good bye good
    bye good
    ************** Input and Output ****************
    Input: good bye
    Output:
    total strings Matched: 5
    whichlinesmatched: 2
    whichlinesmatched: 2
    whichlinesmatched: 3
    whichlinesmatched: 4
    whichlinesmatched: 5
    whichlinesmatched: 0
    whichlinesmatched: 0
    whichlinesmatched: 0
    whichlinesmatched: 0
    whichlinesmatched: 0
    ** but the desired output is 3, and only line 2, 3, 4 matched
    ** Could you please have further help about this? Thank you.
    ************** the codes****************
    import java.io.*;
    public class Tokenize{
    public static void main( String args[] ){
    int maxNumberOfLine = 1000; //the maximium number of line in data file for input
    String fileName = "test"; // file name for data input
    String stringForCount = "good bye"; // specified word for counting
    int totalStringMatched = 0; // number of word matched
    int[] whichLineMatched; // line number for each word matched
    whichLineMatched = new int[maxNumberOfLine];
    // Input string (stringForCount) has been stored in a string array, wordForCompare[]
    // For example: stringForCount = "good bye"
    int stringLength = 2;
    String wordForCompare [] = { "good" , "bye" };
    // wordForCompare[0] = good
    // wordForCompare[1] = bye
    int wordFromFile;
    StreamTokenizer sttkr;
    try{
    FileInputStream inFile = new FileInputStream(fileName); //specifying the file to be opened
    Reader rdr = new BufferedReader(new InputStreamReader(inFile)); //assigned a StreamTokenizer
    sttkr = new StreamTokenizer(rdr);
    sttkr.eolIsSignificant(false);
    System.out.println("Searching for word : " + stringForCount );
    while( (wordFromFile = sttkr.nextToken()) != StreamTokenizer.TT_EOF)
    System.out.println( "going looping through file, token is: " + sttkr.sval );
    if(sttkr.sval.equals(wordForCompare[0])){
    if (stringLength == 1) {
    totalStringMatched++;
    whichLineMatched[totalStringMatched-1]=sttkr.lineno();
    } else {
    for (int p=1; p < stringLength; p++) {
    wordFromFile = sttkr.nextToken();
    System.out.println( sttkr.sval );
    if (!(sttkr.sval.equals(wordForCompare[p])))
    break;
    else if (p==stringLength-1) {
    totalStringMatched++;
    whichLineMatched[totalStringMatched-1] = sttkr.lineno();
    } // end of else
    } // end of for-loop
    } // end of else
    System.out.println( " total strings Matched: " + totalStringMatched );
    } // end of if
    }//end of while for wordFromFile
    for( int i = 0; i < 10; i++)
    System.out.println( "whichlinesmatched: " + whichLineMatched<i> );
    } catch(Exception e) {} //end of try
    }

    A small change to roopa_sree's code, this code fails if there are multiple occurences of the search string in the same line. Make this small change to correct it,import java.io.File;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.StringTokenizer;
    public class WordCounter {
         public static void main(String args[]) throws Exception {
              if(args.length != 1) {
                   System.out.println("Invalid number of arguments!");
                   return;
              String sourcefile = args[0];
              String searchFor = "good bye";
              int searchLength=searchFor.length();
              String thisLine;
              try {
                   BufferedReader bout = new BufferedReader (new FileReader (sourcefile));
                   String ffline = null;
                   int lcnt = 0;
                   int searchCount = 0;
                   while ((ffline = bout.readLine()) != null) {
                        lcnt++;
                        for(int searchIndex=0;searchIndex<ffline.length();) {
                             int index=ffline.indexOf(searchFor,searchIndex);
                             if(index!=-1) {
                                  System.out.println("Line number " + lcnt);
                                  searchCount++;
                                  searchIndex+=index+searchLength;
                             } else {
                                  break;
                   System.out.println("SearchCount = "+searchCount);
              } catch(Exception e) {
                   System.out.println(e);
    }Sudha

  • How to replace a string in a text file?

    Hi All,
    i read one text file and based on that i replaced the old character with the new string but it doesnt works.do any one of you have idea on this?
    My Code:
    String newPassword=(String) getInputText1().getValue();
    String password=(String)getSimNo().getValue();
    String sampleText = (String) getMobileNo().getValue();
    FileReader fr =new FileReader("c:/newLogin.txt");
    BufferedReader br =new BufferedReader(fr);
    String record=br.readLine();
    while (record !=null)
    String[] afterSplit=record.split(":");
    for (int p = 0; p < 1; p++) {
    String userName=afterSplit[1];
    String passWord=afterSplit[3];
    if(userText.equals(userName) && password.equals(passWord)) {
    passWord.replaceAll(passWord,newPassword);
    System.out.println("password: " + password +" changed to : "+ newPassword +" successfully");
    record =br.readLine();
    sample fiile in the text:
    userName:sebas:password:navin
    userName:sebas1:password:navin1

    All readLine does is copy a line of the file into a local variable. Change the copy as you will, the file won't change.
    You need to write a new version of the file, with the altered lines. Then, if required, you can delete the original file and rename the new file to the old file name.

  • Finding multiple strings in a text file and deleting the entire line

    Get-Content c:\output-Copy.txt | Where-Object {$_ -notmatch 'something1', 'something2', 'something3', 'something4' } | Set-Content temp.txt
    Above is the program that when it has 1 argument in the -notmatch part will find the specific string and delete the entire line. I need to be able to use multiple strings for my search, I am totally drawing a blank on this and I know its something REALLY
    simple but my brain is fried. The above code will work IF i only leave 'something1' and delete the rest. I need to find MULTIPLE matches and remove them all at once, what is a good way to accomplish this.

    You can use an alternating regex, like this:
    Get-Content c:\output-Copy.txt |
    Where-Object {$_ -notmatch 'something1|something2|something3|something4' } |
    Set-Content temp.txt
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How to write Strings in a text file with BufferedWriter

    I've got a Vector object full of Strings objects, I'm interested in wrinting these Strings in a text file with a BufferedWriter , I would apreciate some code, thank you

    http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedWriter.html
    "PrintWriter out = new PrintWriter(new BufferedWriter((new FileWriter("foo.out")));"

  • Reading Each String From a text File

    Hello everyone...,
    I've a doubt in File...cos am not aware of File.....Could anyone
    plz tell me how do i read each String from a text file and store those Strings in each File...For example if a file contains "Java Tchnology forums, File handling in Java"...
    The output should be like this... Each file should contains each String....i.e..., Java-File1,Technology-File2...and so on....Plz anyone help me

    The Java� Tutorials > Essential Classes: Basic I/O

  • How to read the content of a text file (by character)?

    Guys,
    Good day!
    I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
    Please help me. Thank you so much in advance.
    Jojo

    http://java.sun.com/javase/6/docs/api/index.html
    package java.io
    InputStream.read(): int
    Reads the next byte of data from the input stream.
    Implementation:
    InputStreamReader
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

  • How to get summary columns in delimited text file

    How to get summary columns in delimited text file
    I am trying to generate a delimited text file output with delimited_hdr = no.The report is a Group above report with summary columns at the bottom.In the text file the headers are not getting repeated & thats ok.The problem is the summary data is getting repeated for each row of data.Is there a way where i will get all the data & summary data will get displayed only once.I have to import the delimited text file in excel spreadsheet.

    Sorry there were a typos :
    When I used desformat=DELIMITEDDATA with desttype=FILE, I get error "unknown printer driver DELIMITEDDATA". When you look for help, DELIMITED is not even listed as one of the values for DESTFORMAT. But if you scroll down and look for DELIMITER it says , this works only in conjuction with DESTFORMAT=DELIMITED !!!!!!??!! This is in 9i.
    Has this thing worked for anybody ? Can anyone please tell if they were able to suppress the sumary columns or the parent columns of a master-detail data for that matter ?

  • How do i split content from the text file using tab and spaces...?

    Hi.. Just want to ask help to all the experts. Im new in java and i have this problem on how to split the contents of the text file. ill show you the contents in order to let you see what i mean.
    FileName: COL.txt
    AcctNo AcctName Primary Secondary Status Opendate
    121244 IPI Company Noel Jose Active 12/05/2007
    As you can see the content i want to split it per column.. Please help me

    Jose_Noel wrote:
    Hi prometheuzz,
    What do you mean by one thread...?You created two threads* with the same question in it. That way, people might end up giving you an answer that has already been posted in your other thread: thus wasting that person's time.
    Just don't create multiple threads with the same question please.
    * a thread is a post here at the forum

  • How to find by DEFAULT the EXACT text string (and no more) with Acrobat Pro?

    How to find by DEFAULT (always) the EXACT text string (and no more) with Acrobat Pro? Adobe Acrobat Pro 9.2.0 search engine finds USELESS hits on Mactel with Mac OS X 10.5.8.
    For instance, if I search for "sec" (no quotes) trying to find ONLY hits with sec (for second, like in: it took 20 sec), it finds useless hits like: security, etc (any word containing sec, which is NOT what I want).

    Any idea on how to do it by default with Adobe Acrobat Pro 9.3.1 on Mac OS X 10.6.2 (Snow Leopard)? Thanks.

  • How to find a string in SAP code

    Hello,
    Does anyone here know how I can find a string inside the SAP code efficiently? I tried finding a custom table name using the Where-used list feature but the results doesn't show the complete/correct results. It missed some user exits where the table name was also used.
    Please help

    Hello Jimmy,
    You can try what Krishna has said there is one more way that is
    goto trxn SE12,
    enter Z* in the table name field,
    it will give a popup box with all the Ztables found in your system...you can find your table maybe it is a little tedious job
    Sravani

  • How to output strings to an text file and excel file

    Hi guys,
    I am writing a simple application taht process some string inputs from user using a simple GUI. The GUI consists of a series of
    textfields which the user can enter names, age, addresses....etc
    Once they complete filling up that GUI form, they click SUBMIT. All the values will then be read. These strings are then required to be output to 2 files
    1. To a text file which I can open it and read it anytime I wish.
    2. To an excel file which follows a specific format. That is, all names will be written to column B, all ages will be written to column C...etc
    The programme is expected to keep running allow the user to enter details of multiple persons(some 300 sets of data of different persons) until he clicks on End program.
    Please advise how I can output the strings to
    1. Text file
    2. Excel file.
    Many many thanks. I need this for one of my project which is due so so soon...... :((
    Regards
    David

    1. Text file
    See link to "Documentation - Tutorials" on the left
    side of this page.
    2. Excel file
    Dont try to write the real excel format (if you want
    to do it soon).
    - write data to a plain text file.
    - Use tab stops for separation of values.
    - Name file as excel file. (*.xls)
    If you double click this file, excel will import data
    and insert it to a table in the right order by
    itself.
    Excel can save this as real .xls now.
    Anyone here with a better idea? (Try to learn by
    myself)good thing to know for the excel tip :)
    thx

  • Finding strings in a text file?

    Hi! i'm learning to read text files. what i want to do with this program is to find word 1-3, 2-4, 3-5... and write them in a system.out.println. i found a program that opens files and count words, lines and characters and tried to adjust it do find three-word strings.
    i can compilate (hope that word exists) but when i run it, it says: Exception in thread "main" java.lang.NoSuchMethodError: main
    anyone who knows what this could depend on?
    This is what the code looks like:
    import java.io.*;
    import java.io.*;
    import java.util.*; //tillagd f�r att removeFirst4 skall funka
    import javax.swing.*; //tillagd f�r att removeFirst4 skall fungera
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    import java.lang.*;
    import javax.swing.*;
    public class AttLaesaEnFil2 {
         private static void samla(String name, BufferedReader in) throws
         IOException {
         String a;
         WordExtractor b;
    String c = " ";
    String d;
    WordExtractor e;
    String f;
    String g;
    WordExtractor h;
    String i;
    String j;
    String k;
    String l;
    String line;
    do {
                   line = in.readLine();
                   if (line != null)
    b = new WordExtractor(line);
         c = b.getFirst();
         d = b.getRest();
         e = new WordExtractor(d);
         f = e.getFirst();
         g = e.getRest();
         h = new WordExtractor(g);
         i = h.getFirst();
         j = h.getRest();
         k = c + f + i;
         l = c + " " + f + " " + i;
         System.out.println("The first three words are: " + l);
         a = b.getRest();
    while (line != null);
              System.out.println("Klart!");
              private static void samla(String fileName) {
              BufferedReader in = null;
              try {
                   FileReader fileReader = new FileReader(fileName);
                   in = new BufferedReader(fileReader);
                   samla(fileName, in);
              } catch (IOException ioe) {
                   ioe.printStackTrace();
              } finally {
                   if (in != null) {
                        try {
                             in.close();
                        } catch (IOException ioe) {
                             ioe.printStackTrace();
         private static void samla(String streamName, InputStream input) {
              try {
                   InputStreamReader inputStreamReader = new InputStreamReader(input);
                   BufferedReader in = new BufferedReader(inputStreamReader);
                   samla(streamName, in);
                   in.close();
              } catch (IOException ioe) {
                   ioe.printStackTrace();
    Thanx in advance!

    this may be a stupid question but i'll give it a
    shot. ...do i replace my private static void with
    public static void or do a add the public?Whether you replace one of your methods or create a new one is up to you, but you have to have a method with this exact signature:
    public static void main(String[] foo) {
    }(The variable name can be different of course)

  • How to find a string inside Excel table

    Hi,
    I am trying to find a string inside Excel table, and it does not work. Please see attached figure. I use the find Invoke Node and do not get anthing.
    Please help
    Attachments:
    find_excel.JPG ‏21 KB

    See attached files.
    Thanks,
    David
    Attachments:
    Excel_table.xls ‏15 KB
    Read_XL.vi ‏42 KB

  • How to find zeros in a spred sheet file

    I have a spread sheet file having 33 column I want to find  is there any zero in any of the columns,how this can be done easily.searching one dimensional array is time consuming since file size is very large
    thanks for your time
    regards
    augustin
    Certified LabVIEW Associate Developer
    Solved!
    Go to Solution.

    johnsold wrote:
    If the spreadsheet file is a text file, you could use the string functions to search for the presence of zeros.  The details would depend heavily on the format in which the data is saved.
    For working with numeric values another caution is in order.  In this case it probably would work to use the Is Equal to Zero comparison primitive, but remember that in general equality comparisons on floating point numbers are not a good idea due to the finite representation in binary and roundoff errors after calculations.  Adapting Matt Bradley's suggestion you might test whether the absolute value is less than some tolerance, such as 1e-6, rather than zero.
    Lynn 
    Lynn- good point! but use abs val and compare to the machine epsilon  (that "little e" constant on the numeric>constants sub-palette is the smallest value that the computer can represent as a dbl)
    Jeff

Maybe you are looking for

  • How do I get Apple to pay attention to IOS Mail Signature Issues?!!!!!

    IOS Signature..... OK, so I know this has been answered a number of times before and I have posted this at the request of senior advisors at Apple Customer Service who are also fed up with people complaining about the lack of basic functionality with

  • Washed out colour

    Hi Everyone     When i try to alter washed out colour in my footage using Shadow/Highlight or Gamma ,i get a comb effect on the edge of the subject and if i use auto colour or auto levels ,the colour isn't stable.I need a really good solution to the

  • Invalid number in viber

    i have reinstall and install  the viber in to my phone but it still says invalid number . i have used viber in any other device. pls can anyone help me ?

  • Applications directory excluded from backups

    Hi all, My time machine is not backing up correctly. It is exlcuding the Applications directory and I'm unable to do a system restore from it. Does any one have any solutions to this. FYI, I've checked exclusion lists etc. plus there's plenty of spac

  • Is there a keyboard shortcut to "Pin as App Tab"?

    Sometimes (mainly with a touchpad) moving the mouse cursor to the tab, right-clicking and choosing "Pin as App Tab" is a lot of work compared to just using a keyboard shortcut. Is there a keyboard shortcut to do this?