You didn't say perl, but here's a one-liner that does what you want...

# cat deb.csv
DEBIT,20100208120000[0:GMT],      \
DEBIT,20100208120000[0:GMT],       \
DEBIT,20100204120000[0:GMT],        \
DEBIT,20100125120000[0:GMT],         \
DEBIT,20100125120000[0:GMT],         / rest of lines trimmed
DEBIT,20100122120000[0:GMT],        /
CREDIT,20100120120000[0:GMT],     /
CHECK,20100119120000[0:GMT],


# perl -pe '$_ = "$1,$2_$3_$4_$5$6\n" if
(/(\S+),(\d{4})(\d{2})(\d{2})(\d{6})(.*)/);' < deb.csv
DEBIT,2010_02_08_120000[0:GMT],      \
DEBIT,2010_02_08_120000[0:GMT],       \
DEBIT,2010_02_04_120000[0:GMT],        \
DEBIT,2010_01_25_120000[0:GMT],         \
DEBIT,2010_01_25_120000[0:GMT],         / rest of lines trimmed
DEBIT,2010_01_22_120000[0:GMT],        /
CREDIT,2010_01_20_120000[0:GMT],     /
CHECK,2010_01_19_120000[0:GMT],


-Steve



On Thu, Mar 18, 2010 at 10:11 PM, Thomas Taylor <li...@comcast.net> wrote:

> I import a comma separated list from my bank and open it in OOcalc.  I have
> trouble reading the date in their format of YYYYMMDDhhmmss, it's all glommed
> together.  I want to run a script on it before importing that will put some
> character (prefer either "_" or " " as shown below.
>
> DEBIT,20100208120000[0:GMT],      \
> DEBIT,20100208120000[0:GMT],       \
> DEBIT,20100204120000[0:GMT],        \
> DEBIT,20100125120000[0:GMT],         \
> DEBIT,20100125120000[0:GMT],         / rest of lines trimmed
> DEBIT,20100122120000[0:GMT],        /
> CREDIT,20100120120000[0:GMT],     /
> CHECK,20100119120000[0:GMT],    /
>    ^         ^
>        date field (YYYYMMDDhhmmss)
>
> DEBIT,2010_02_08_120000[0:GMT],  <<<<< end result I want
>
> pass 6 or 7 char then find ","
> then 4 digits for year
> insert "_"
> then 2 digits for month
> insert "_"
> then 2 digits for day
> insert "_"
> get rest of line
>
> Tried combinations of sed & awk but haven't been able to insert the "_"
> between the year, month, day, and time fields.
>
> Pointers and suggestion would be greatly appreciated.  I'm in the process
> of learning bash scripting so please include how the script works (what it
> does).  I'm an old hand at C and assembler but the bash/sed/awk syntax has
> me baffled.
> --
> Thanks, Tom (retired penguin)
> openSuSE 11.3-M3, kde 4.4.0
> FF 3.6.0
>



-- 
Steve McCarthy
   s...@mccrew.com
   mcc...@gmail.com

Reply via email to