You are not logged in.

#1 2011-07-22 16:32:37

darkbeanies
Member
Registered: 2009-01-14
Posts: 142

[SOLVED]Help generating a .csv file for GCStar

Hello, I want to make a script that makes .csv files automatically.  And i thought to myself, "where can I ask some gifted individuals how to do this?"

Okay, enough buttkissing!  :-)

I'm using gcstar to catalog my horrendous data collection.  Starting with my zxspectrum games!

So, here's what I need:
field1;field2;etc;etc (i know these, it's just a single line at the top of the file)
;;;;;;;;FILE-NAME-WITHOUT-FILE-EXTENSION;;ZX SPECTRUM;;;;;;;;;FULL-PATH-TO-FILE;;;FULL-PATH-TO-DIRECTORY;;;;;;;;;;;;;;
;;;;;;;;FILE-NAME-WITHOUT-FILE-EXTENSION2;;ZX SPECTRUM;;;;;;;;;FULL-PATH-TO-FILE2;;;FULL-PATH-TO-DIRECTORY;;;;;;;;;;;;;;

etc

For a whole bunch of files in a directory.

Anyone know how I can do this please?

Done it!  I knew there were some gifted invididuals here!  Only took me a few hours, too!

#!/bin/bash

#FINAL VERSION

ls -1 /games/path | sed 's/\(.*\)\..*/\1/' > ~/output1

cat output1 | sed 's/^/;;;;;;;;/' > ~/output2

cat output2 |sed 's/$/;;ZX SPECTRUM;;;;;;;;;/' > ~/output3

ls -d -1 /games/path/*.* > ~/output4

paste -d"\0" ~/output3 ~/output4 > ~/output5

cat output5 | sed 's/$/;;;/' > ~/output6

sed -e 's/$/\/games\/path;;;;;;;;;;;;;;/' output6 > madness.csv

rm output1 output2 output3 output4 output5 output6

Last edited by darkbeanies (2011-07-22 21:48:27)

Offline

#2 2011-07-23 03:46:27

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: [SOLVED]Help generating a .csv file for GCStar

You probably don't need this anymore, but the following script is equivalent to yours but is a little more efficient.  (I hope I got the right number of semi-colons.)

#!/bin/bash

path="/game/path"
cd "$path"

for game in *
do
    no_extension="${game%.*}"
    echo ";;;;;;;;${no_extension};;ZX SPECTRUM;;;;;;;;;${path}/${game};;;${path};;;;;;;;;;;;;;"
done

Offline

#3 2011-07-23 04:17:59

darkbeanies
Member
Registered: 2009-01-14
Posts: 142

Re: [SOLVED]Help generating a .csv file for GCStar

Your script made me sad because it's so much more elegant than mine.  And, I think the whole endeavour is flawed somehow anyway.

My hard drive is a shambles, apart from the archlinux operating system partition, which is eerily well organized.

:-(

Offline

Board footer

Powered by FluxBB