There is no standardized format for Linux text output, which is not easy to watch. Today, I have studied the following format: awk;
awk '{printf "%-18s%-8s%-8s%-8s%-55s%-30s%-50s\n",$1,$2,$3,$4,$5,$6,$7}' cpu.log > cpu_$tsSuf.log
If you want to modify the source file in the shell, you can export it to a temporary file, format the output, and then export it to the specified file
Delete the temporary file at the end of shell;
Today, I wrote a script to generate patrol text and regularly export it to a file every day;
#!/bin/bash #append department ts=$(date -d '24 hours ago' +'%Y-%m-%d %H:%M:%S') tsSuf=$(date -d '24 hours ago' +'%Y_%m_%d') YearM=$(date +'%Y%m') mysql --login-path=localhost -e "select h.ip,m.disk,count(*) as times,h.role,h.domain,h.erp,h.organizationFullName from jd_dbmonitor.db_host as h, jd_dbmonitor.machine_data_$YearM as m where h.id=m.host_id and disk > 80 and m.add_time > '$ts' and h.role='M' and h.db_type<>1 group by h.ip ;" > disk.log awk '{printf "%-18s%-8s%-8s%-8s%-55s%-30s%-50s\n",$1,$2,$3,$4,$5,$6,$7}' disk.log > disk_$tsSuf.log mysql --login-path=localhost -e "select h.ip,m.diskio,count(*) as times,h.role,h.domain,h.erp,h.organizationFullName from jd_dbmonitor.db_host as h, jd_dbmonitor.machine_data_$YearM as m where h.id=m.host_idand diskio > 50 and h.role='M' and h.db_type<>1 group by h.ip order by times desc;" > io.log awk '{printf "%-18s%-8s%-8s%-8s%-55s%-30s%-50s\n",$1,$2,$3,$4,$5,$6,$7}' io.log > io_$tsSuf.log mysql --login-path=localhost -e "select h.ip,m.cpu,count(*) as times,h.role,h.domain,h.erp,h.organizationFullName from jd_dbmonitor.db_host as h, jd_dbmonitor.machine_data_$YearM as m where h.id=m.host_id andcpu > 90 and h.role='M' and h.db_type<>1 group by h.ip order by times desc;" > cpu.log awk '{printf "%-18s%-8s%-8s%-8s%-55s%-30s%-50s\n",$1,$2,$3,$4,$5,$6,$7}' cpu.log > cpu_$tsSuf.log /bin/rm cpu.log io.log disk.log echo "$ts cpu/disk/io has output success."