Results 1 to 3 of 3
  1. #1
    clrgomes is offline Member
    Join Date
    Mar 2011
    Location
    Brazil
    Posts
    2
    Rep Power
    0

    Thumbs up [SOLVED]Printing indexOf line

    Hello,
    Please could anyone help me to find a better way to print a specific line in the text.

    For instance, I have a Router interface configuration:
    !
    interface TenGigE0/0/0/0.200
    bandwidth 1000
    service-policy input QOS_IN
    service-policy output QOS_OUT
    ipv4 address X.X.X.X 255.255.255.252
    encapsulation dot1q 200
    !

    Using indexOf function, I know that some line is configured, now I need to print a specif line (service-policy output QOS_OUT).

    How can I do that?
    Thanks in advance

    CLRGomes
    Last edited by clrgomes; 03-06-2011 at 08:14 AM. Reason: [SOLVED]

  2. #2
    clrgomes is offline Member
    Join Date
    Mar 2011
    Location
    Brazil
    Posts
    2
    Rep Power
    0

    Thumbs up [SOLVED] Printing indexOf line

    Hi Guys
    I got a solution, I don't know if it is the best one.

    String [] linha1 = result.split("\n"); //break the text in lines
    for (int i=0;i<linha1.length;i++)
    {
    if(linha1[i].indexOf("service-policy") != -1) //Read each line looking for this string
    {
    String [] linha2 = linha1[i].split(" "); //If found, break line in spaces
    print ("QoS "+linha2[2]+" Configurado: "+linha2[3]); //print the specific fields
    }
    }

    It works fine, if someone have a better solution please let me know
    Thanks

    CLRGomes
    Last edited by clrgomes; 03-06-2011 at 08:16 AM. Reason: [SOLVED]

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,432
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by clrgomes View Post
    Hi Guys
    I got a solution, I don't know if it is the best one.

    [ ... ]

    It works fine, if someone have a better solution please let me know
    You could read each line with a LineNumberReader; when you've found what you're looking for that LineNumberReader can tell you the number (index) of the line.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. printing 3 elements in an array on 1 line
    By Symbiot in forum New To Java
    Replies: 2
    Last Post: 05-27-2010, 12:29 PM
  2. Having trouble with printing a blank line.
    By Meta in forum New To Java
    Replies: 4
    Last Post: 05-11-2010, 10:54 PM
  3. Log4j not printing out file and line number
    By devin in forum Java Servlet
    Replies: 2
    Last Post: 03-05-2009, 03:16 PM
  4. Issue with printing line
    By Azndaddy in forum Advanced Java
    Replies: 1
    Last Post: 04-04-2008, 07:37 PM
  5. Printing command line arguments
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:27 AM

Posting Permissions

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