The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to store the data retrived by a select query into variables? jisha Shell Programming and Scripting 12 01-17-2008 11:45 PM
Howto capture data from rs232port andpull data into oracle database-9i automatically boss UNIX for Dummies Questions & Answers 1 09-23-2007 03:35 AM
How to store Data in a File krishna_sicsr Shell Programming and Scripting 2 06-09-2007 09:23 AM
Extracting data from each line csaha Shell Programming and Scripting 1 04-27-2006 12:49 AM
extracting info from Unix database to construct a visual diagram fusion99 UNIX for Advanced & Expert Users 0 11-30-2004 01:29 AM

Closed Thread
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 01-25-2008
mam mam is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 6
extracting data and store in database

Hello all,
I have this text file data. The data are separated by comma in three column and space or line feed to start a new row
Code:
anderson helberg, Jane, brother
Sister ,mother,grandpa
bombay,new york, china
I would like store them in the following format.
Code:
field1                           field2                              field3
anderson helberg              Jane                               brother
bombay                         new york                         china
my problem is how to implemet the script with both line feed or single space or multiple space and comma separator to separate the rows and stores the data as shown above.
by using cut and delimiter.
Code:
anderson helberg=`echo "$text" | cut -f 1 -d','`
please anyone with help appreciated
  #2 (permalink)  
Old 01-29-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Your example doesn't match the description though,,, 'space or line feed to start a new row' isn't what you show. Your example shows it starting a new row on line feed only, and treating space as part of the field.
I'll use the output (ie line feed seperation only) as the goal here.

You can cheat and just use sed to substitute commas for tabs but it won't make a very pretty layout.
Otherwise, printf would probably be the way to go here:
Code:
#!/bin/sh
printf "%10s    %10s    %10s\n" "field1" "field2" "field3"
while read line
do
    printf "%10s    %10s    %10s\n" "`echo $line | cut -d ',' -f 1`" "`echo $line | cut -d ',' -f 2`" "`echo $line | cut -d ',' -f 3`"
done
  #3 (permalink)  
Old 01-29-2008
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
Can you try this out
(You have to work out in order to format properly)
echo "field1 field2 field3"
while IFS="," read a b c
do
echo "$a $b $c"
done < FileName
Closed Thread

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 01:56 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