Tag Info

Hot answers tagged

3

If you have the GNU implementation of awk or mawk 1.3.4-20121129 or newer, try: $ awk ' { split($2,a,"/"); split($3,b,":"); split(strftime("%m/%d/%Y %H:%M:%S",mktime(a[3]" "a[1]" "a[2]" "b[1]" "b[2]" "b[3])),c); $2 = c[1]; $3 = c[2]; print; } ' file AA 09/07/2014 02:30:38 PM AA0000011111 08 Y A Jane, Doe AA 09/07/2014 11:30:31 AM ...


2

You could also use sed: sed -e :1 -e 's|^\([^:]*[ /]\)\([0-9][/:]\)|\10\2|;t1' Inserts a 0 before any single digit in between a space or / and / or : in the part leading to the first :.


2

You specify the width and zero padding using printf modifiers in awk: $ awk -F'[/:]| +' '{ printf "%s %02d/%02d/%02d %02d:%02d:%02d %s %-13s %s %s %s %s %s %s\n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15 } ' input_file AA 09/07/2014 02:30:38 PM AA0000011111 08 Y A Jane, Doe AA 09/07/2014 11:30:31 AM AA0000011112 09 ...



Only top voted, non community-wiki answers of a minimum length are eligible