Results 1 to 2 of 2

Thread: awk in Java

  1. #1
    Join Date
    Jun 2016
    Posts
    7
    Rep Power
    0

    Default awk in Java

    For example I have a String value here.
    Java Code:
    String info = "house:tree:blue:snow:324:Santa Claus:beets:";
    I want to save any (first, third) field of delimiter ":" into a String variable.
    Java Code:
    String second = "tree";
    String fifth = "324";
    String sixth = "Santa Claus";
    I want to save only one of those values. For example, in Bash I would use awk.
    Java Code:
    awk -F ":" '{print $1}'  // would grab "house"
    awk -F ":" '{print $5}'  // would grab "324"
    And then save that value into a single String variable.
    Is there something similar in Java?

  2. #2
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: awk in Java

    Take a look at the .split() method of the String class, you can specify ":" as the delimiting regular expression.


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
  •