help with sed
Joep L. Blom
jlblom at neuroweave.nl
Wed Jun 27 22:04:31 UTC 2012
On 27-06-12 08:03, Nils Kassube wrote:
>
> I'm not a sed-wizard either, but this is what I would use:
>
> ~/> echo '1,8,2011,10,0,a,b,c,...'|sed -e s/,/-/ -e s/,/-/ -e s/,/\ / -e s/,/:/ -e s/,/:0,/
> 1-8-2011 10:0:0,a,b,c,...
>
>
> Nils
Nils,
Thanks for your reply. I have made a small bash-script with it and it
works as expected. However, I also want the first line - which has the
headers - also changed so that the first three headers are change to
date and the next two to time. However, the script I made and expected
to work doesn't. The script part with your solution works OK.
This is my script:
_______________________________________________________________
#!/bin/bash
#Simple program make the first 5 fields in a .csv-file into a date time
format
echo "$1 en $2"\n;
sed -e '1,1s/day,month,year/date/' -e '1s/hour,minute/time/' -e
'2,$s/,/-/' -e '2,$s/,/-/' -e '2,$s/,/\ /' -e '2,$s/,/:/' -e
'2,$s/,/:0,/' $1 > $2;
_____________________________________________________________
It doesn't give errors but line one is not changed. Perhaps you can see
my error? In the result file line 1 is unchanged.
Joep
More information about the ubuntu-users
mailing list