How to print specific lines out of a Tail - N command.

Hello,
Here is my problem. Within a web application, one of the menu is supposed to do the following:
Check the n lastest lines of a file (a log file in fact) and print the lines that only contain "ADD" or "DEL"
I don't know how to do it ! Please, help !!

This should get you started, it's a java version of tail which takes multiple files and there roll extension and runs forever (hopefully!).
* @author Jeff Hackert, Jon Strabala
import java.io.*;
import java.util.*;
public class TailIt extends Thread {
    private BufferedReader br = null;
    private Thread thread;
    private long rollTime = 0L;
    private String fname = null; // the log file
    private String rname = null; // the rolled log file
    private static boolean debug = false;
    private static synchronized void stdOut(String line) {
        System.out.println(line);
    public void run() {
        String s = null;
        boolean attail = false;
        long prev = System.currentTimeMillis();
        try {
            for(;;) {
                s = br.readLine();
                if ( s != null ) {
                    if (attail) {
                        TailIt.stdOut(s);
                } else {
                    attail = true;
                    try {
                        sleep(10);
                        long now = System.currentTimeMillis();
                        if (now > prev + 5000) { // checks roll every five seconds
                            prev = now;
                            checkRoll();
                    } catch (InterruptedException ioe) {}
                yield();
        } catch (IOException ioe) {}
    public void setRollTime() {
        File f = new File(fname);
        if (f.exists()) {
            rollTime = f.lastModified();
        } else {
            rollTime = 0;
    public void checkRoll() {
        long tmpTime = 0L;
        File f = new File(rname);
        if (f.exists()) {
            tmpTime = f.lastModified();
        if (rollTime < tmpTime) { //a roll occurred
            Date d = new Date(rollTime);
            stdOut("Log " + fname + " rolled at " + d.toString());
            try {
                br.close();
                br = new BufferedReader(new FileReader(fname));
            } catch (Exception e) {}
            setRollTime();
        } else {
            if (debug) System.err.println("no roll at " + rollTime + " " + tmpTime);
    public static void main(String [] args) {
        if (args.length != 0) {
            for (int i = 0; i < args.length; i = (i + 2)) {
                if ((i + 1) == args.length) {
                    System.err.println("Usage: TailIt <log file> <roll extension> ...");
                    System.exit(0);
                TailIt m = new TailIt();
                try {
                    m.fname = args;
m.br = new BufferedReader(new FileReader(m.fname));
m.rname = m.fname + "." + args[i + 1];
m.setRollTime();
m.thread = new Thread(m);
m.thread.start();
} catch (FileNotFoundException e) {
System.err.println(e);
} else {
System.err.println("Usage: TailIt <filename> <roll extension> <filename> <roll extension> ...");

Similar Messages

  • How to print specific pages out of a book file

    I've searched around but I cannot find any way of printing specific pages out of a book file. Has anyone got any ideas? I have a 100 page book file with 20 files, and doing print outs of sections is a nightmare. I want to be able to print page 5 out of file A and page 6 out of file B together so I can duplex them. I've tried scripting this but I can't seem to set the page range of the print preferences of the book file.

    [Jongware] wrote:
    I don't think it's possible to set the page range of a Book.printPreferences
    Theoretically it ought to be possible. Can't test for myself now; what does happen when you set the pageRange to overlapping sub-files?
    I've just tried it with CS3. It might have been implemented in later versions.
    In the print Book dialogue the page range field is disabled. You cannot enter anything there.
    If you try to do it with a script it says that printPreferences is read only.

  • How to print new line in jsp page

    hi
    how to print new line in jsp page
    thanks

    \n - new line character is in java specific not HTML
    specific.Well, if the correct line separator sequence (by far not always \n) would be used, it does add a new line to the HTML output. Too bad that you don't want to see HTML but formatted text. The BR tag is a formatting element for the displayed text, not a line break in HTML. ;)

  • How to read specific line in a file through UNIX shell script..

    Dear Friends,
    I have generated .ldt file under admin/import/US folder through FND_LOAD script for Download the responsibility.
    I registred Shell script (Host concurrent program) in Oracle apps. Now i want to read the file in speciific line which i was generated in admin/import/US folder through unix shell script. Please help me how to read specific line and the i want to replace that which i am going to read the specific line.
    Thanks in advance..
    Regards,
    Velu.

    Hi,
    Thanks for reply,
    My requirement i have to find the specific line in a file and find and replace needed word over there it's should happen programatically. i want to read specific line in a file Once complete find and replace the condition should exists. The loop will go to next file and read the same line in next file also do the same process upto how many files over there.i am doing through UNIX shell script. Please help me out to find the
    Your suggestion is highly appriciated.
    Thanks,
    Velu.

  • How to print horizantal lines in smartforms?

    hi friends,
                       how to print horizantal lines in smartforms.
    waiting for ur valuble replies.
    Thanks,
    Kiran

    HI,
    If u use templates or table,then use borders to print the horizontal lines.
    Eg : Create template-->Table painter->click select pattern button->Display framed pattern->select 3rd one.it will display only horizantal lines.
    if want to print horizantal line under the text, then create one paragraph or character formate with Underline in smartstyles.Use that paragraph or character to u r text element

  • How to print vertical lines for line items?

    hi experts,
                    can any one tell me how to print vertical lines for line items in ascript?
    ive tried using sy-vline but its printing jus one line each for each item .i want it in columns ?if there are any control commands plz let me know how to print?
    thanks &regards
    narendar

    hi narendar,
    Welcome to SDN.
       u can go for box command.
    Use the box command with zero width for vertical lines.
    Position the line by x position and y postion.
    syntax :
    BOX <xpos> <ypos>
           <width>
          <height>
          <thickness in twips> twips.
    Regards,
    Arun.
    Reward points if useful.

  • How to print specific concurrent request to specific printer in R12

    Good Day,
    How to print specific concurrent request to specific printer in R12,
    when i try to make specific printer to the user it's print all requests.
    i need to do this for one request only and print this request once.
    is there any profile option for this case.
    Thanks.

    any updates

  • How to search specific text/string in pdf files from command prompt?

    Hi,
    How to search specific text/string in pdf files from command prompt?
    Will be great if you can refer to any adobe provided command base utility to achieve the above target.
    Best Regards,

    You can't. The commandline parameters for Acrobat and Adobe Reader do not allow any type of commands to be run.

  • How to print header lines at the top of every page with Alv list display?

    Dear all,
    I need a requirement with printing issue. A program list should be printed with the function reuse_alv_list_display.
    The list has several pages and then can be printed but the header lines appear only first page when they printed. The other pages don't have header lines, they continue with the next record of the list remaining from previous page. I use the alv parameters as below:
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = l_repid
          i_callback_pf_status_set = 'ALV_PF_STATUS'
          is_layout                = ls_layo
          it_fieldcat              = lt_fcat
          i_default                = 'X'
          i_save                   = 'A'
          is_variant               = ls_variant
          it_events                = lt_events
        TABLES
          t_outtab                 = lt_data
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
    and lt_events as below:
      ls_event-name = 'END_OF_LIST'.
      ls_event-form = 'ALV_END_OF_LIST'.
      APPEND ls_event TO lt_events.
      ls_event-name = 'END_OF_PAGE'.
      ls_event-form = 'ALV_END_OF_PAGE'.
      APPEND ls_event TO lt_events.
      ls_event-name = 'TOP_OF_LIST'.
      ls_event-form = 'ALV_TOP_OF_LIST'.
      APPEND ls_event TO lt_events.
      ls_event-name = 'TOP_OF_PAGE'.
      ls_event-form = 'ALV_TOP_OF_PAGE'.
      APPEND ls_event TO lt_events.
    So, how can I print header lines for every page?
    Best Regards,

    Hello Saba,
    Your point might be very close to solution.
    Because in the selection screen of the program there are two radio buttons, one of them visits 'REUSE_ALV_COMMENTARY_WRITE' function and the other doesn't. The one which visits has a problem with header liens in every page when printing. But I couldn't find out the solution yet.
    reuse_alv_list_display uses 4 event and of course I call subroutine. There are end_of_list, end_of_page, top_of_list and top_of_page. I use in the subroutine for top_of_page:
      CALL FUNCTION 'LVC_TRANSFER_TO_SLIS'
        EXPORTING
          it_fieldcat_lvc         = gt_fcat
        IMPORTING
          et_fieldcat_alv         = lt_fcat
        EXCEPTIONS
          it_data_missing         = 1
          it_fieldcat_lvc_missing = 2
          OTHERS                  = 3.
      CALL FUNCTION 'REUSE_ALV_LIST_WIDTH_GET'
        EXPORTING
          it_fieldcat = lt_fcat
        IMPORTING
          e_width     = l_width.
    WRITE l_reptx TO l_reptx CENTERED.
      NEW-LINE.
      WRITE: AT (l_width) l_reptx CENTERED.
      SUBTRACT 10 FROM l_width.
      WRITE: AT l_width sy-pagno RIGHT-JUSTIFIED.
        CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
          EXPORTING
            it_list_commentary       = lt_header
      I_LOGO                   =
      I_END_OF_LIST_GRID       =
    Do you have other suggestions ?

  • How to print break line in jsp.

    in jsp where a bean.getProperty() value has a broken line. but it displays as a single line in the web page. when printing the line by System.out.println() statement, it displays as a verious new line where '\0' is applied but in jspbean.getProperty it does not.
    For example :
    It displays by SOP()statement as
    Successful
    No error
    No restarts
    No marked completed
    but in web page it displays as
    Successful No error No restarts No marked completed.
    please provide the code that support in jsp file so that the output statement should like as SOP()statement output type.
    Thanks in advance.
    Uttam

    I guess you want to display CRLF (\r\n) in JSP?
    Line breaks in HTML are generally represented as < br >.
    You have 3 options:
    1) replace CRLF by < br >.
    2) style the line using CSS with 'white-space' set to 'pre'.
    3) surround the line with the HTML < pre > tag.

  • How to print new line in webdynpro

    Friends,
    I want to print a success message in new line, the below shown is a one singe line and want to split two lines.
    I used this:
    wdComponentAPI.getMessageManager().reportSuccess("Example : this is the test message i would like to print in two lines, some how it is not working please help me how to "+
    "/n/n print this in two new lines.")
    when i execute the above code it is displaying on screen as succsess message as below shown in one line:
    Example : this is the test message i would like to print in two lines, some how it is not working please help me how to print this in two new lines.
    But my requirement expecting  some thing below shown:
    Example : this is the test message i would like to print in two lines, some how it is not
    working please help me how to print this in two new lines.

    really? how?   Ó.o

  • How to print 20 lines in one page and remaining lines in another in script?

    Hi I created 2 pages in script for page1 next page is page2 , how i can print 20 lines in one page and remaining in next page plz send me the code for that and is windows same for 2 pages?...

    Hi Krishna,
    Try below code...
        CALL FUNCTION 'OPEN_FORM'
        EXPORTING
          form                              = form.
        CALL FUNCTION 'START_FORM'
        EXPORTING
         language               = sy-langu
         startpage              = page1
      LOOP AT itab.
        count = count + 1.
        item = count mod 20.
        IF item EQ '1' AND count NE '1'.
           CALL FUNCTION 'END_FORM'.
           CALL FUNCTION 'START_FORM'
           EXPORTING
             language               = sy-langu
             startpage              = <b>page2</b>
        ENDIF.
       "write_form statement ....
      ENDLOOP.
    Message was edited by:
            Hikaruno

  • M602n Laserjet - How to print 66 lines in DOS

    Running an old DOS program in virtual XP mode and need to print 66 lines instead of 60.  On older HP Laserjet IIIsi, I could just change the setting on the printer manually at the printer itself.  How do i change this setting on an  M602 printer?

    This seems to be a commercial product. For the best chance at finding a solution I would suggest posting in the forum for HP Business Support!
    You can find the Commercial Laserjet board here:
    http://h30499.www3.hp.com/t5/Printers-LaserJet/bd-p/bsc-413
    Best of Luck!
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • How to print continue Line Numbers  in PLD  Differen repetitve areas.

    Hi,
    We need to print line numbers continues in different Repetitive areas.
    Ex. Repetitve Area 0 we have item Discriptions
          Repetitve Area  Footer1 we created sotvalue() here it will display servicetaxes
          Repetitve Area Footer1 we created one text roundoff
    we need output like
    Ex:1. Dell        **Repetitve Area 0****           
          2.Mouse     **Repetitve Area 0****           
          3.Laptop      **Repetitve Area 0****             
          4.servicetax   **Repetitve Area Footer1****           
          5.cess             **Repetitve Area Footer1****           
          6.Hcess             **Repetitve Area Footer1****           
          7.Roundoff           **Repetitve Area Footer1****    as a text field       
      for above all we need to print Line numbers sequence how we can print sequence numbers for differen  areas.if i  assigned Linenum( ) in Repetitve Area 0 it will display one for Repetitve Area 0 only.and i applied Gouplinenum also it's not printing. please guide me how to print this.
    regds,
    sampath kumar devunuri.

    Hi,clint pow.
    Please we did what you said but we are not retreiving data.please tell me how we can get serieal numbers for different repetitve areas.
    regds,
    sampath.

  • Need help in how to print new line character in unix using java

    Hi All,
    I use the printstream class to print some line in a text using java.
    here is the code:
       FileOutputStream out; // declare a file output object
            PrintStream p; // declare a print stream object
                    p.print("\t");
                    p.print(date);
                    p.print("\t\t");
                    p.print(RecCount);
                    p.println("\n");when i use this and output of this character in windows is
    date RecCount
    22-07-2007 23456
    when i use the same code in unix it shows the following output:
    date RecCount[]22-07-2007
    it wont accept the new line character could any one give me an idea to solve this problem.

    PrintStream has a println() method. Use that. Or System.getProperty("line.separator").
    Because a newline char doesn't necessarily specify a line break. It's system-dependent.

Maybe you are looking for

  • Query for daily sales by warehouse

    Hi I need a query for   Daily sales by warehouse.  I am only new to this and struggling with generating. ideally it will look like the below.     With no selection criteria as I would like to schedule the report to email out at the end of each day. W

  • How do I split my albums in iPhoto, so not albums to bee seen, only 1?

    How do I split, or seperate, my albums in iPhoto, so not all albums can be seen at once?? This, if I send the link to someone, about +one specific album+. Some albums are for other eyes only....... Now, it seems, that everybody can see ALL the albums

  • Error -3256 attempting to use multiple Speakers

    I have the option for multiple speakers and I have updated my airport express firmware on both AX's. However when attempting multiple speakers I get an error -3256 for each AX. Both AX's work fine individually. I am on 10.4.8 and iTunes 7.1 Anybody w

  • How to automatically delete iCal events

    I've finally gotten to a "technical place" where I have an iMac, MacBook Pro, iPad, and iPhone for my wife and I.  Life is good!! I've made the switch to iCloud and now manage my calendar on all devices, but I can't seem to find how to set up my cale

  • Everything new at once (including the newbie), a newbie's nightmare

    OK, I should have someone local who can help me, but I don't. Hopefully this forum can! I'm an old fashioned pen and staff paper composer upgrading to the 21st century because I've been asked to score a 30 minute documentary in May. So after weeks of