Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8348213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:37:34+00:00 2026-06-09T07:37:34+00:00

I have an output of a command that basically lists a bunch of key/value

  • 0

I have an output of a command that basically lists a bunch of key/value pairs inside of it. The output is in no obvious format, therefore I think regex will be the best approach.

Output: http://pastebin.com/Hfu4nP3M

Basically, I need to store the key/value pairs (comma seperated) from lines 21-30 and store them in a map.

Is it possible to do this using regex?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:37:35+00:00Added an answer on June 9, 2026 at 7:37 am

    I am not sure if that is what you want, but since you said that you need to store the key/value pairs (comma seperated) from lines 21-30 which are

     {memory,
         [{total,38751504},
          {processes,13711212},
          {processes_used,13711198},
          {system,25040292},
          {atom,662409},
          {atom_used,653371},
          {binary,287088},
          {code,18209655},
          {ets,1358504}]},
    

    I assumed that you want to read values after memory that are stored inside [...].

    To do this you can use something like

    //creating reader to get data from file
    BufferedReader in = new BufferedReader(new InputStreamReader(
            new FileInputStream("data.txt")));// file with your data
    
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = in.readLine()) != null) {
        sb.append(line.trim());// also remove unnecessary tabulators and
                                // spaces
    }
    in.close();
    
    String data = sb.toString();
    
    Pattern pattern = Pattern.compile("\\{memory,\\[(.*?)\\]");
    Matcher m = pattern.matcher(data);
    if (m.find()) {
        Pattern keyValuePattern = Pattern.compile("\\{(\\w*?),(\\d*?)\\}");
        Matcher matcher = keyValuePattern.matcher(m.group(1));
        while (matcher.find())
            System.out.println(matcher.group(1) + "->" + matcher.group(2));
    } else
        System.out.println("not found");
    

    Output

    total->38751504
    processes->13711212
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute a command, have the output of that command get gzip'd
Well, the subject says it all, basically. I have a command-line utility that may
Possible Duplicate: Running a command from Ruby displaying and capturing the output I have
I have output from grep I'm trying to clean up that looks like: <words>Http://www.path.com/words</words>
I have a char byte that I want to convert to an int. Basically
I have a tool that generates tests and predicts the output. The idea is
I have a Windows program that has a GUI which also uses a command
Basically I'm making a command prompt GUI. User sees command prompt output in a
Basically I have a command which will copy the contents of a source directory
I'm trying to write a C program that grabs command output and then i'll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.