Possible solution
sed 's/^....-\(..\)-\(..\)/\2.\1/'
These multiple dots may not be elegant; the command doesn't care if it deals with numbers; it doesn't care if there is something more in the first "column". These issues can be fixed with more complex approach, but in its current form the command is quite straightforward.
The general command sed 's/A/B/'
replaces pattern A
with B
, at most once per line.
Where A
in this case consists of:
^
– the beginning of a line marker,
....
– exactly four characters,
-
– literal -
,
(..)
– exactly two characters referenced later with \1
,
-
– literal -
,
(..)
– exactly two characters referenced later with \2
.
And B
is
\2
– whatever was in the second ()
in A
,
.
– literal .
,
\1
– whatever was in the first ()
in A
.
Additionally (
and )
are escaped by \
.
To process a file add it as the last argument. To process a file in place use -i
, e.g.
sed -i 's/^....-\(..\)-\(..\)/\2.\1/' myfile.txt