Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Need Help in arranging the output

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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, 20 views)
File Type: txt Output_File.txt (72 Bytes, 21 views)
Sponsored Links
    #2  
Old Unix and Linux 10-23-2012
bartus11's Unix or Linux Image
bartus11 bartus11 is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 3 August 2016, 11:03 AM EDT
Posts: 3,733
Thanks: 7
Thanked 1,152 Times in 1,122 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 Unix and Linux 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 Unix and Linux 10-25-2012
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 28 July 2016, 6:37 AM EDT
Location: India
Posts: 1,413
Thanks: 101
Thanked 497 Times in 474 Posts
Use /usr/xpg4/bin/awk or nawk on Solaris.
Sponsored Links
    #5  
Old Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 02:37 AM.