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 8687621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:09:46+00:00 2026-06-12T23:09:46+00:00

First, if there is a better title for this question, I am all ears!

  • 0

First, if there is a better title for this question, I am all ears!

Is there a better way of doing this?

I have a data file input.txt in this format:

field1=value1
field2=value2
field3=value3
.
.
.
field1=value4
field2=value5
field3=value6

and so on … and would like to end up with:

field1,value1 value4 ... valueM
field2,value2 value5 ... valueN
field3,value3 value6 ... valueO

What I’ve tried:

  1. Generate unique keys: cat input.txt |awk -F"=" '{print $2}' |sort -u > data_key

  2. Loop over rows in data_key

#!/bin/bash

file=input.txt
keys=`cat data_key`

for value in $keys
do
  output=`cat $file |grep $value |awk -F"=" '{print $2}' |tr -s '[:space:]' '[ *]' `
  echo $value, $output
done
  • 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-12T23:09:47+00:00Added an answer on June 12, 2026 at 11:09 pm

    The below awk-based solution should work. This uses associative arrays keyed by field names. Values are concatenated as they are encountered.

    awk -F'=' '{z[$1]=z[$1]" "$2} END{for(i in z){print(i","z[i])}}' file_name.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, my apologies for the title of this question, I don't have
First question is, Am I on the right path?.ıs there a better way to
First of all there is probably a question like this already but i couldn't
First of all I'd welcome edits to the title of this question, I couldn't
First of all, the title of this question is horrible, but I didn't find
Is there any way to first test if a file is in use before
First, I'm sorry for the question title but I can't think of a better
There are several questions throughout this post all related to the title. The overall
First of all, sorry for the question title - I was unable to think
First off I'm not sure that's the proper title for this question but hopefully

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.