On Thu, 18 Mar 2010, Thomas Taylor wrote:
> 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
This looks familiar...
$ cat > input
DEBIT,20100208120000[0:GMT],whatever
DEBIT,20100208120000[0:GMT],whatever
DEBIT,20100204120000[0:GMT],whatever
DEBIT,20100125120000[0:GMT],whatever
DEBIT,20100125120000[0:GMT],whatever
DEBIT,20100122120000[0:GMT],whatever
CREDIT,20100120120000[0:GMT],whatever
CHECK,20100119120000[0:GMT],whatever
^D
$ perl -lpe '
# -l preservse the line endings from the input, not really important here
# -p prints out the input lines after we mangle them below
# -e execute this little bit of code
s{
# make a substitution pattern
# whitespace and comment will be ignored because of the 'x' at the end
, # the first comma
(\d{4}) # year (stored in $1)
(\d\d) # month (stored in $2)
(\d\d) # day (stored in $3)
}
{,$1_$2_$3_}msx; # put it back together
' < input
DEBIT,2010_02_08_120000[0:GMT],whatever
DEBIT,2010_02_08_120000[0:GMT],whatever
DEBIT,2010_02_04_120000[0:GMT],whatever
DEBIT,2010_01_25_120000[0:GMT],whatever
DEBIT,2010_01_25_120000[0:GMT],whatever
DEBIT,2010_01_22_120000[0:GMT],whatever
CREDIT,2010_01_20_120000[0:GMT],whatever
CHECK,2010_01_19_120000[0:GMT],whatever
It works.
--
Andrew B. Sweger -- The great thing about multitasking is that several
things can go wrong at once.