newbie question - sorting a vertical list into a csv format

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 2
Reputation: c7borg is an unknown quantity at this point 
Solved Threads: 0
c7borg c7borg is offline Offline
Newbie Poster

newbie question - sorting a vertical list into a csv format

 
0
  #1
Nov 12th, 2008
Hi guys, I'm looking to start scripting and have a problem I thought I would use to learn some basics, basically I have a list of my family's addresses that are in one big vertical list varying in size. I want to sort into a tabular format below is a example of the list

I'm looking into how to sort through a list, and print each element into a line under the right category heading (using comma's as a separator) then using a blank as a prompt for the script to move onto the next bunch of data in the list (in this case contact details) putting that on a new line

Thanks in advance

bob smith
43 canarvon road
worcester
WD2 4 XY
Tel:0800 000 000
Email:get@me.co.uk

john doe
56 victoria street
little hampton
hamtonshire
Email:the@there.com

lilly allen
94 Dames close
Simsville
Essex
Phone:0909811811

I would like to sort it as follows(csv format):
name, address1, address2, address3, address4, email, phone
bob smith, 43 canarvon road, worcester, WD2 4 XY, , Email:get@me.co.uk, Tel:0800 000 000
john doe, 56 victoria street, little hampton, hamtonshire, ,the@there.com, ,
lilly allen, 94 Dames close, Simsville, Essex,,, Phone:0909811811
Last edited by c7borg; Nov 12th, 2008 at 11:30 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

Re: newbie question - sorting a vertical list into a csv format

 
0
  #2
Nov 13th, 2008
sounds like homework to me!! You had a go at it at all. You should try man sed.
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: c7borg is an unknown quantity at this point 
Solved Threads: 0
c7borg c7borg is offline Offline
Newbie Poster

Re: newbie question - sorting a vertical list into a csv format

 
0
  #3
Nov 13th, 2008
Originally Posted by chris5126 View Post
sounds like homework to me!! You had a go at it at all. You should try man sed.
no not at my age.. but I will have a look at the manual
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

Re: newbie question - sorting a vertical list into a csv format

 
0
  #4
Nov 13th, 2008
lol sorry just have seen very similar if not exactly the same problem before!! Look through this forum and you should find the answer somewhere.
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: newbie question - sorting a vertical list into a csv format

 
0
  #5
Nov 14th, 2008
Originally Posted by chris5126 View Post
lol sorry just have seen very similar if not exactly the same problem before!! Look through this forum and you should find the answer somewhere.
(while read line; do if [ $(echo $line | wc -c) -eq 1 ] ; then echo; else echo -n $line,; fi ; done<address.txt ) |sort >address.csv
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC