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: Phil
Subject: Re: [Help-bash] Bash read specific element from csv
Date: Tue, 7 Oct 2014 23:46:40 +0200
User-agent: Unison/2.1.10

Hello

Thanks for this suggestion/solution!

The following part is working smoothly:
{ read; read; IFS=';' read date _; } < Euronext.csv
date=${date//\"/}
read d m y <<< "$date"
filename="Euronext $y${month[$m]}$d.csv"
echo "<$filename>"


I understand that the statement "read; read;" ensures the positioning at the 3rd line where the date stamp is located. For my general knowledge, how would the code look like if the date stamp was located at the end of the file or at line 25?

Unfortunately, the system I am using runs Bash 3.2. I am currently searching Bash 3.2 equivalent to associative arrays. It appears that I have somewhat a bone to chew on to find a working equivalent.

Thanks
Best regards,


Phil

On 2014-10-07 18:29:02 +0000, Greg Wooledge said:

On Tue, Oct 07, 2014 at 08:03:44PM +0200, Phil wrote:
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

OK.  I was afraid you would go on to say something like "And then I
need to read each line after that, and extract the Hoog field, ..."

<--------- SNAP --------->
"Naam";"ISIN";"Symbol";"Market";"Trading
Currency";"Open";"Hoog";"Laag";"Last";"Last Date/Time";"Time
Zone";"Volume";"Turnover"
"European Equities";"";;;;;;;;;;;
"28 Sep 2014";;;;;;;;;;;;

The only semi-difficult thing at this point is converting Sep to 09.
That can be done with an associative array in Bash 4.

declare -A month
i=1
for m in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec; do
    printf -v "month[$m]" %02d $((i++))
done

{ read; read; IFS=';' read date _; } < Euronext.csv
date=${date//\"/}
read d m y <<< "$date"
filename="Euronext $y${month[$m]}$d.csv"
echo "<$filename>"






reply via email to

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