[Top][All Lists]

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

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

From: Phil
Subject: Re: [Help-bash] Bash read specific element from csv
Date: Tue, 7 Oct 2014 20:03:44 +0200
User-agent: Unison/2.1.10


The objective is simply for filenaming purposes. The file of which a snapshot is given underneath comes in everyday. When the file is received it is always called Euronext.csv. The objective is simply to read the data stamp in the third row first column (28 Sep 2014), and rename the file from Euronext.csv to Euronext 28 Sep 2014.csv or even better Euronext 20140928.csv

Indeed a simple question, but unfortunately one I have not found the answer to just yet.
Best regards,


On 2014-10-07 14:09:59 +0000, Greg Wooledge said:

On Tue, Oct 07, 2014 at 02:11:55PM +0200, Phil wrote:

I am struggling to find the bash code to read a specific element from a
CSV.   The csv is constructed as follows:
<--------- SNAP --------->
Currency";"Open";"Hoog";"Laag";"Last";"Last Date/Time";"Time
"European Equities";"";;;;;;;;;;;
"28 Sep 2014";;;;;;;;;;;;
"All datapoints provided as of end of last active trading day.";;;;;;;;;;;;
"BETER BED";"NL0000339703";"BBED";"Euronext
"ROBERTET CI";"FR0000045601";"CBE";"Euronext
<--------- 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]