help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Bash read specific element from csv


From: Greg Wooledge
Subject: Re: [Help-bash] Bash read specific element from csv
Date: Tue, 7 Oct 2014 10:09:59 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Oct 07, 2014 at 02:11:55PM +0200, Phil wrote:
> Hello,
> 
> I am struggling to find the bash code to read a specific element from a 
> CSV.   The csv is constructed as follows:
> <--------- SNAP --------->
> "Naam";"ISIN";"Symbol";"Market";"Trading 
> Currency";"Open";"Hoog";"Laag";"Last";"Last Date/Time";"Time 
> Zone";"Volume";"Turnover"
> "European Equities";"";;;;;;;;;;;
> "28 Sep 2014";;;;;;;;;;;;
> "All datapoints provided as of end of last active trading day.";;;;;;;;;;;;
> "IDI";"FR0000051393";"IDIP";"Euronext 
> Paris";"EUR";"23.42";"23.50";"23.42";"23.42";"26/09/2014 
> 12:00";"CET";"21";"492.98"
> "BETER BED";"NL0000339703";"BBED";"Euronext 
> Amsterdam";"EUR";"16.80";"16.80";"16.48";"16.645";"26/09/2014 
> 17:35";"CET";"1206";"20106.64"
> "ALCATEL-LUCENT";"FR0000130007";"ALU";"Euronext 
> Paris";"EUR";"2.494";"2.504";"2.446";"2.486";"26/09/2014 
> 17:39";"CET";"15581702";"38683091.21"
> "FIPP";"FR0000038184";"FIPP";"Euronext 
> Paris";"EUR";"0.08";"0.08";"0.08";"0.08";"26/09/2014 
> 10:35";"CET";"20001";"1600.08"
> "ROBERTET CI";"FR0000045601";"CBE";"Euronext 
> Paris";"EUR";"101.70";"101.70";"101.70";"101.70";"23/09/2014 
> 12:00";"CET";"40";"4068.00"
> ...
> <--------- SNAP --------->

Your email program (or your text editor) has mangled the format somewhat.
I can't tell how many fields there are supposed to be per line.

But given the rest of the question, I guess that doesn't matter:

> I want bash to read the first element on the third line, containing the 
> date (ie 28 Sep 2014), and return into a string.

And then what?  What's the rest of the question?  This is too easy.
There has to be more.

{ read; read; IFS=';' read date _; } < yourfile
date=${date//\"/}   # to strip the quotation marks

Now that I have answered this question, I *know* the question is going
to change, and I wish you had asked it all at once, so we can start over
and do what you really want.

(Once you change the question, this answer will become useless, and
you'll just throw it away, and take a *completely* different approach to
parsing the data file.  And then the actual layout of the file is going
to matter, so we'll have to reverse engineer what the file actually
looks like before the mangling, etc.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]