python3天数转日期

!/usr/bin/env python3
– coding:utf-8 –
import time
import os
import sys
print()
input_num_value = int(input(“请输入转换的天数:”))
time_convert_value = input_num_value * 24 * 60 * 60 #天转秒
time_cur_value = time.time() #当前日期的秒
time_convert_mes = time_cur_value + time_convert_value #求秒+当前秒=和秒
time_day = time.gmtime(time_convert_mes) #转换日期
time_day_format = time.strftime(“%Y-%m-%d %H:%M:%S”,time.gmtime(time_convert_mes))
print()
print(‘天数转换后的年月日: {}’.format(time_day_format))
print()

awk数字过滤

netstat -lntp|awk {'print $4'}|awk -F ':' '{if ($NF~/^[0-9]$/) print $NF}'|sort|uniq 
netstat -lntp|awk '{print $4}'|awk -F ':' '/[0-9]/{print $NF}'|sort|uniq
netstat -lntp|awk {'print $4'}|awk -F ':' '{print $NF}'|egrep "^[0-9]$"|sort|uniq

结果:

22
3306

为什么执行这句无任何显示

netstat -lntp|awk {‘print $4’}|awk -F ‘:’ ‘/^[0-9]*$/{print $1}’|sort|uniq

但在txt文本又能生效

[root@oldboy scripts]# cat test.txt 
(only
Local
22
a3306
22
3306
4473f
56789
[root@oldboy scripts]#  cat test.txt|awk -F ':' '/[0-9]/{print $1}'|sort|uniq 
22
3306
4473f
56789
a3306
[root@oldboy scripts]#  cat test.txt|awk -F ':' '/^[0-9]$/{print $1}'|sort|uniq 
[root@oldboy scripts]# cat test.txt|awk -F ':' '/^[0-9]*$/{print $1}'|sort|uniq
22
3306
56789

总结:

  • netstat 不需要多次匹配
  • cat 需要多次匹配
  • netstat 是一行处理 cat 是多行处理