[Techtalk] text parsing question
Conor Daly
conor.daly-linuxchix at cod.homelinux.org
Thu Oct 26 19:33:32 UTC 2006
On Thu, Oct 26, 2006 at 10:27:32AM -0700 or so it is rumoured hereabouts,
gossamer axe thought:
> Hi!
>
> I have a text file that looks like
> ,
> question
> ,answer
> ,question2
> ,answer2
> ,
This file looks inconsistent from here. Is it the case that there is no
comma on a line by itself between ,answer and ,question2 ? If so you have
a harder task. If there is always a comma by itself on a line, you have a
suitable separator.
> So either making the text file automatically bring up two bottom lines to
> the first or someway of importing newline delimited fields into mysql. I
> suppose a bash script to read each line in and maybe write it to a file
> $var1,$var2,$var3 on one line.
This would be my approach, not from any innate superiority of the method,
more from a lack of sed knowledge. My bash script would do something
like:
exec < file
read LINE
echo $LINE | grep '^,$' > /dev/null
if [ $? .eq 0 ]; then
read LINE2
read LINE3
echo "$LINE $LINE2 $LINE3" > outfile
fi
and something to iterate over the file...
Conor
--
Conor Daly <conor.daly at cod.homelinux.org>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/G/S/O d+(-) s:+ a+ C++(+) UL++++ US++ P>++ L+++>++++ E--- W++ !N
PS+ PE Y+ PGP? tv(-) b+++(+) G e+++(*) h-- r+++ z++++
------END GEEK CODE BLOCK------
http://www.geekcode.com/ http://www.ebb.org/ungeek/
More information about the Techtalk
mailing list