User Tools

Site Tools


sed:convert:convert_date_format:convert_date_format

SED - Convert - Convert Date Format

A file having dates in format “ 10/31/20”, and want to convert it to 31/10/2020.

sed 's#\([0-9][0-9]\)/\([0-9][0-9]\)/\([0-9][0-9]\)#\2/\1/20\3#' filename
 
sed -E 's#([0-9]{2})/([0-9]{2})/([0-9]{2})#\2/\1/20\3#' filename

To cater for cases where the month or day is a single digit, such “ 1/31/20” then change the {2} to {1,2}.


sed/convert/convert_date_format/convert_date_format.txt · Last modified: 2020/12/03 19:03 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki