Article title: slow execution speed: use shell to process MB files. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Code:
#! /Bin/bash
While IFS = ', 'Read things_before date_string things_after; do
# Remove double quote
Date_string = $ (echo $ date_string | sed's/\ "// g ')
# Parse eache field
Year =$ {date_string: 0: 4}
Month =$ {date_string: 4: 2}
Day =$ {date_string: 6: 2}
Hour =$ {date_string: 8: 2}
Minute =$ {date_string: 10: 2}
Second =$ {date_string: 12: 2}
Millisecond =$ {date_string: 14}
Millisecond = $ (printf "% 06d" $ millisecond)
Echo-n $ things_before
Echo-N ',"'
Echo-n "$ year-$ month-$ day $ hour: $ minute: $ second. $ millisecond"
Echo-n '",'
Echo $ things_after
The code in done can process more than one hundred kb of files, but it is very slow to process at 1 MB level. Let's see if it can be optimized. where is it not reasonable? Thank you.