The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
convert a pipe delimited file to a':" delimited file priyanka3006 Shell Programming and Scripting 6 05-26-2009 11:53 AM
Convert comma text file to Column in html format sriram003 Shell Programming and Scripting 9 03-31-2009 09:16 AM
Help needed to convert delimited to CSV format karthikd214 Shell Programming and Scripting 5 02-05-2009 01:42 PM
how to convert the result of the select query to comma seperated data - urgent pls Hemamalini Shell Programming and Scripting 1 06-16-2008 05:27 AM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 09:24 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-28-2009
natalie23 natalie23 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 15
Urgent! need help! how to convert this file into comma delimited format

Hi experts,
I need urget help! I have the a text file with this format:

Types of fruits
Name of fruits
1,1
Farm_no,1
apple,1
pineapple,1
grapes,1
orange,1
banana,1
2,2--->this is the record seperator
Farm_no,2
apple,1
pineapple,1
grapes,3
orange,2
banana,1
3,3--->this is the record seperator
Farm_no,3
apple,4
pineapple,2
grapes,3
orange,2
banana,0

I need to parse this txt file into csv format.

The output need to look like this:

FARM_no,apple,pineapple,grapes,orange,banana
1,1,1,1,1,1
2,1,1,3,2,1
3,4,2,3,2,0

Anyone have any idea?Please help!

Thank a lot!

Thanks.
  #2 (permalink)  
Old 08-28-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,311
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
  #3 (permalink)  
Old 08-28-2009
natalie23 natalie23 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 15
Hi Zaxxon,

I have tried the above thread using awk but unsuccessful:
#!/bin/bash
echo "FARM_no,apple,pineapple,grapes,orange,banana'
awk -F "," '{ print $2}' text file

But I am not sure how to use the RS, since the record seperator is different and how to start form the 3rd line.

Thanks
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0