help with sed
Nils Kassube
kassube at gmx.net
Thu Jun 28 06:21:10 UTC 2012
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
More information about the ubuntu-users
mailing list