python调shell遇到换行时,awk之类的切割符号会导致出错,特别是以下的情况

因为左列特长引起了不必要的换行,需要用脚本进行处理
值得注意的是fs_output必须是未进行awk切割的结果,要是提前使用df -h|grep -v Filesystem| awk 'length($5)!=0 { print $2,$3,$(NF-1),$NF}'获取fs_output,那么后期python无论如何处理fs_output都不对,因为源数据就已经乱了
new_output=[]
list_length=0
newfu=''
for fu in fs_output.split('\n'):
length=len(fu.split())
list_length+=length
if length==6:
new_output.append(fu)
list_length=0
elif list_length==6:
newfu=newfu.rstrip('\n')+' '+fu.strip()
new_output.append(newfu.strip())
list_length = 0
newfu=''
else:
newfu = newfu.rstrip('\n') +' '+fu.strip()
fs_output=new_output
2、巨坑2:
Windows2008系统版本显示密码配置如下:
密码最短使用期限 (天): 0 密码最长使用期限 (天): 42
Windows7系统版本显示密码配置如下:
密码最短使用期限(天): 0
密码最长使用期限(天): 42
少了一个空格,坑爹
浙公网安备 33010602011771号