![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 08:45 PM |
| Howto capture data from rs232port andpull data into oracle database-9i automatically | boss | UNIX for Dummies Questions & Answers | 1 | 09-22-2007 11:35 PM |
| How to store Data in a File | krishna_sicsr | Shell Programming and Scripting | 2 | 06-09-2007 05:23 AM |
| Extracting data from each line | csaha | Shell Programming and Scripting | 1 | 04-26-2006 08:49 PM |
| extracting info from Unix database to construct a visual diagram | fusion99 | UNIX for Advanced & Expert Users | 0 | 11-29-2004 10:29 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 Code:
field1 field2 field3 anderson helberg Jane brother bombay new york china by using cut and delimiter. Code:
anderson helberg=`echo "$text" | cut -f 1 -d','` |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|