When using sed to calculate log time, some netizens encountered the following problem: log time is recorded incorrectly, and each log is slowed down by 12 hours, so the time to restore each log. Of course, it is easier to use more advanced languages such as awk and python. His requirement is to use sed, so here is a sed solution. Log sample: 1.1.1.1 20120523045959/xxx. do? Product = xxx & xxx = 8.6-"xxxx/1.6.0 (Linux; U; xxxx1.0.4; xxxBuild/xxx)" sed code: sed-nr 'H; s # ^ ([^] *) (. {8 })(..) (..) (..) (. *) $ # echo-n \ 1 $ (date-d "\ 2 \ 3: \ 4: \ 5 12 hours "+" % Y % m % d % H % M % S ") # e; G; s/\ n [^] *. {14} // P' execution result: [root @ station1 ~] # Echo '1. 1.1.1 20120523045959/xxx. do? Product = xxx & xxx = 8.6-"xxxx/1.6.0 (Linux; U; xxxx1.0.4; xxxBuild/xxx)" '| sed-nr' h; s # ^ ([^] *) (. {8 })(..) (..) (..) (. *) $ # echo-n \ 1 $ (date-d "\ 2 \ 3: \ 4: \ 5 12 hours "+" % Y % m % d % H % M % S ") # e; G; s/\ n [^] *. {14} // P' 1. 1.1.1 20120523165959/xxx. do? Product = xxx & xxx = 8.6-"xxxx/1.6.0 (Linux; U; xxxx1.0.4; xxxBuild/xxx )"