LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2019, 08:06 AM   #1
Snehasish
LQ Newbie
 
Registered: Apr 2019
Posts: 1

Rep: Reputation: Disabled
Concat one column values in loop bashed on other column


I am creating a report where i am getting the memory module name and the status of the same. I have written the code to get the HTML file which is giving me output like attached image

Code:
Current OP :
Servername             Module           Status
xxxxxxx                1                3
xxxxxxx                2                3  
xxxxxxx                3                3  
xxxxxxx                5                1  
xxxxxxx                6                1
Below is my code

Code:
FS=","
print "=============================="
printf "<h3>ServerName:%s</h3>", server
print "=============================="
print  "<HTML>""<TABLE border="1">"
}
 {
printf "<TR>"
for(i=1;i<=NF;i++)
{
printf "%s", "<td"
if ($i+0==2) printf " bgcolor=#FF3333"
    else if ($i+0==1) printf " bgcolor=#FFCC33"
    else if ($i+0==4) printf " bgcolor=#99FF33"
print ">" $i "</td>"
}
print "</TR>"
 }
END{
print "</TABLE></BODY></HTML>"
 }
' Report.html
But need the output like all the module with same status should come in comma separated manner in a single row.

Code:
Expected :  
Servername             Module           Status
xxxxxxx                1,2,3            3
xxxxxxx                5,6              1
Please let me know how to achieve this
 
Old 04-01-2019, 08:55 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
You'll have to make one pass through the data and collect all the statuses. Then in the END{} clause, print them out, not before. AWK works quite well for this but perl is much easier in some ways.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Perl to count number of matches in one column based on values in another captainentropy Programming 16 12-19-2013 02:12 PM
Menu bashed shell script for users shell 0.o Linux - Server 6 02-14-2013 06:00 AM
How to display 2 different column field values as one column value in mysql VijayaRaghavanLakshman Linux - General 2 04-16-2012 09:56 AM
String concat in for loop onyxbird Slackware 4 08-16-2011 02:19 AM
[SOLVED] echo concat values abercrombieande Programming 12 05-23-2011 09:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration