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: 16 April 2014, 6:09 PM EDT
Posts: 3,679
Thanks: 6
Thanked 1,131 Times in 1,104 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  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 15 April 2014, 12:52 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 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 02:15 PM
arranging columns with AWK sramirez Shell Programming and Scripting 2 12-12-2010 02:06 PM
need help in arranging the alias upengan78 Shell Programming and Scripting 4 07-09-2010 04:29 PM
Re-arranging lines of text... help? shorte85 UNIX for Dummies Questions & Answers 2 02-26-2009 12:54 PM
Arranging files Vivek788 Shell Programming and Scripting 2 06-07-2008 10:18 PM



All times are GMT -4. The time now is 11:49 PM.