Need Help in arranging the output | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Need Help in arranging the output

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
Sudeep Bhattad Sudeep Bhattad is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 5 November 2012, 4:23 AM EST
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Need Help in arranging the output

Hello All,

Please find attached input and output files. I want to write a shell script to achieve this. I tried using awk but not getting how to do this as I am new to shell programming.

Thanks
Attached Files
File Type: txt Input_File.txt (103 Bytes, 19 views)
File Type: txt Output_File.txt (72 Bytes, 20 views)
Sponsored Links
    #2  
Old 10-23-2012
bartus11's Avatar
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 24 November 2014, 7:00 PM EST
Posts: 3,720
Thanks: 7
Thanked 1,147 Times in 1,118 Posts
Try:
Code:
awk -vRS= '{a[$1]=a[$1](a[$1]?",":"")$2}END{for (i in a) print i","a[i]}' file

The Following User Says Thank You to bartus11 For This Useful Post:
Sudeep Bhattad (10-25-2012)
Sponsored Links
    #3  
Old 10-25-2012
Sudeep Bhattad Sudeep Bhattad is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 5 November 2012, 4:23 AM EST
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
when I am running the command that you have given me, it is throwing some errors :-

awk: syntax error near line 1
awk: illegal statement near line 1
    #4  
Old 10-25-2012
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 9 October 2014, 4:50 PM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts
Use /usr/xpg4/bin/awk or nawk on Solaris.
Sponsored Links
    #5  
Old 10-25-2012
Sudeep Bhattad Sudeep Bhattad is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 5 November 2012, 4:23 AM EST
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
As I specified in the output file attached, I need an output like this -

sudeep,kapil,ritesh
...

and I am getting the output like this -

,
kapil,
ritesh,
sudeep,

Please tell me how should I modify the command....and if you don't mind, please explain the command once as I am new to scripting.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Arranging data bobo UNIX for Dummies Questions & Answers 3 01-20-2012 03:15 PM
arranging columns with AWK sramirez Shell Programming and Scripting 2 12-12-2010 03:06 PM
need help in arranging the alias upengan78 Shell Programming and Scripting 4 07-09-2010 05:29 PM
Re-arranging lines of text... help? shorte85 UNIX for Dummies Questions & Answers 2 02-26-2009 01:54 PM
Arranging files Vivek788 Shell Programming and Scripting 2 06-07-2008 11:18 PM



All times are GMT -4. The time now is 01:15 AM.