help with sed

Johnny Rosenberg gurus.knugum at gmail.com
Thu Jun 28 15:16:00 UTC 2012


2012/6/28 Normand Marion <normand.marion at gmail.com>:
> It could be easier with awk
>
> awk -F"," '{printf "%02d-%02d-%02d %02d:%02d ", $1, $2, $3, $4, $5; for ( i
> = 6; i <= NF; i++ ) printf "%s", $i; printf "\n"}' your_file
>
> or put that code in a file t.awk
>
> BEGIN { FS="," }
> {
>     printf "%02d-%02d-%02d %02d:%02d ", $1, $2, $3, $4, $5
>     for ( i = 6; i <= NF; i++ )
>         printf "%s", $i
>     printf "\n"
> }
>
> and execute awk -f t.awk your_file

I realise that I should take the time to learn awk. Do you know of any
good tutorials?



Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

>
>
> 2012/6/28 Nils Kassube <kassube at gmx.net>
>>
>> Joep L. Blom wrote:
>> > 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.
>>
>> Two remarks:
>> - I don't see a reason to use "1,1s…" for the first command, "1s…"
>> should suffice.
>> - The backslash for the fifth command is not needed because the
>> expression is now inside quotes.
>>
>> But of course that doesn't explain why line 1 is unchanged. I would
>> assume that the expressions you used don't match, e.g. because the
>> original line uses upper case instead of the lower case in your
>> expression or extra space characters somewhere. If you don't find the
>> reason, could you post the original first line of the file?
>>
>>
>> Nils
>>
>> --
>> ubuntu-users mailing list
>> ubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
>
>
> --
> Normand Marion
>
> normand.marion at gmail.com
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>




More information about the ubuntu-users mailing list