将行转为列,将列转为行
Transpose rows to columns and columns to row
我有以下代码用于将行转置为列
awk '/VE464 V4.1.06/{if(s){print s;s=[=10=]}else{s=[=10=]}}
/Normal Acq/{s=s";"[=10=]}
/SL/{s=s";"[=10=]}
/SN/{s=s";"[=10=]}
/Gps Status/{s=s";"[=10=]}
/GPGGA/{s=s";"[=10=]}
/GNGSA/{s=s";"[=10=]}
/GPZDA/{s=s";"[=10=]}
/PTNL/{s=s";"[=10=]}
/TB/{s=s";"[=10=]}
END{print s}' input.txt
我的输入数据是这样的(input.txt):
% VE464 V4.1.06
% Normal Acq
% SL : 30391.00
% SN : 48097.00
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27
% GNGST : $GNGST,034403.00,0.001,0.053,0.046,127.2,0.049,0.050,0.017*44
% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67
% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C
% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30385.00
% SN : 48161.00
% Gps Status : $GPGGA,035229.00,2059.52294297,N,05034.93435481,E,5,16,0.7,201.012,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.5,0.7,1.4*2F
% GNGST : $GNGST,035229.00,0.002,0.053,0.046,136.0,0.050,0.049,0.017*4A
% GPZDA : $GPZDA,035229.01,25,11,2017,00,00*6B
% PTNL : $PTNL,GGK,035229.00,112517,2059.52294297,N,05034.93435481,E,12,16,1.5,EHT168.672,M*43
% TB : 17/11/25 03:52:17:180000 [13937180000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30387.00
% SN : 48161.00
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F
% GNGST : $GNGST,035313.00,0.001,0.053,0.046,138.5,0.050,0.049,0.017*4A
% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63
% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F
% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30389.00
% SN : 48161.00
% Gps Status : $GPGGA,035348.00,2059.55364804,N,05034.93016495,E,5,15,0.7,199.466,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,87,79,65,66,88,78,,,,,,,1.6,0.7,1.4*24
% GNGST : $GNGST,035348.00,0.001,0.053,0.046,138.4,0.050,0.049,0.016*44
% GPZDA : $GPZDA,035348.01,25,11,2017,00,00*6D
% PTNL : $PTNL,GGK,035348.00,112517,2059.55364804,N,05034.93016495,E,12,15,1.6,EHT167.125,M*46
% TB : 17/11/25 03:53:36:380000 [14016380000 microsec]
然后我的代码得到的输出是(行转置为由 ; 分隔的列)
% VE464 V4.1.06;% Normal Acq ;% SL : 30391.00;% SN : 48097.00;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27;% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67;% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C;% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30385.00;% SN : 48161.00;% Gps Status : $GPGGA,035229.00,2059.52294297,N,05034.93435481,E,5,16,0.7,201.012,M,-32.341,M,1.0,0000*6;% Gps Status : $GPGGA,035229.00,2059.52294297,N,05034.93435481,E,5,16,0.7,201.012,M,-32.341,M,1.0,0000*6;% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.5,0.7,1.4*2F;% GPZDA : $GPZDA,035229.01,25,11,2017,00,00*6B;% PTNL : $PTNL,GGK,035229.00,112517,2059.52294297,N,05034.93435481,E,12,16,1.5,EHT168.672,M*43;% TB : 17/11/25 03:52:17:180000 [13937180000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30387.00;% SN : 48161.00;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F;% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63;% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F;% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30389.00;% SN : 48161.00;% Gps Status : $GPGGA,035348.00,2059.55364804,N,05034.93016495,E,5,15,0.7,199.466,M,-32.341,M,1.0,0000*;% Gps Status : $GPGGA,035348.00,2059.55364804,N,05034.93016495,E,5,15,0.7,199.466,M,-32.341,M,1.0,0000*;% GNGSA : $GNGSA,A,3,87,79,65,66,88,78,,,,,,,1.6,0.7,1.4*24;% GPZDA : $GPZDA,035348.01,25,11,2017,00,00*6D;% PTNL : $PTNL,GGK,035348.00,112517,2059.55364804,N,05034.93016495,E,12,15,1.6,EHT167.125,M*46;% TB : 17/11/25 03:53:36:380000 [14016380000 microsec]
在我对之前的输出进行一些处理后,我将得到(干净的输出):
% VE464 V4.1.06;% Normal Acq ;% SL : 30391.00;% SN : 48097.00;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27;% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67;% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C;% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30387.00;% SN : 48161.00;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F;% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63;% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F;% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
然后,使用以前的文件将喜欢从列转置为行,保持与原始文件相同的格式 (input.txt )
最终输出应该是这个:
% VE464 V4.1.06
% Normal Acq
% SL : 30391.00
% SN : 48097.00
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27
% GNGST : $GNGST,034403.00,0.001,0.053,0.046,127.2,0.049,0.050,0.017*44
% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67
% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C
% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30387.00
% SN : 48161.00
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F
% GNGST : $GNGST,035313.00,0.001,0.053,0.046,138.5,0.050,0.049,0.017*4A
% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63
% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F
% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
如果这可以改进并且更容易,并且使用最后一个(干净的输出)从列到行的转置,你会检查我的代码以从行到列转置吗?
你不需要太多的编程!
$ tr ';' '\n' <file
会完成这项工作,除非我错过了一些细节?!
% VE464 V4.1.06
% Normal Acq
% SL : 30391.00
% SN : 48097.00
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27
% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67
% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C
% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30387.00
% SN : 48161.00
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F
% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63
% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F
% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
在记录之间添加一个空行
$ sed '$!G' file | tr ';' '\n'
假设记录之间有一个空行,转换为列可以简化为
$ awk -F'\n' -v RS= -v OFS=';' -v ORS='\n' '{=}1' file
我有以下代码用于将行转置为列
awk '/VE464 V4.1.06/{if(s){print s;s=[=10=]}else{s=[=10=]}}
/Normal Acq/{s=s";"[=10=]}
/SL/{s=s";"[=10=]}
/SN/{s=s";"[=10=]}
/Gps Status/{s=s";"[=10=]}
/GPGGA/{s=s";"[=10=]}
/GNGSA/{s=s";"[=10=]}
/GPZDA/{s=s";"[=10=]}
/PTNL/{s=s";"[=10=]}
/TB/{s=s";"[=10=]}
END{print s}' input.txt
我的输入数据是这样的(input.txt):
% VE464 V4.1.06
% Normal Acq
% SL : 30391.00
% SN : 48097.00
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27
% GNGST : $GNGST,034403.00,0.001,0.053,0.046,127.2,0.049,0.050,0.017*44
% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67
% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C
% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30385.00
% SN : 48161.00
% Gps Status : $GPGGA,035229.00,2059.52294297,N,05034.93435481,E,5,16,0.7,201.012,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.5,0.7,1.4*2F
% GNGST : $GNGST,035229.00,0.002,0.053,0.046,136.0,0.050,0.049,0.017*4A
% GPZDA : $GPZDA,035229.01,25,11,2017,00,00*6B
% PTNL : $PTNL,GGK,035229.00,112517,2059.52294297,N,05034.93435481,E,12,16,1.5,EHT168.672,M*43
% TB : 17/11/25 03:52:17:180000 [13937180000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30387.00
% SN : 48161.00
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F
% GNGST : $GNGST,035313.00,0.001,0.053,0.046,138.5,0.050,0.049,0.017*4A
% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63
% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F
% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30389.00
% SN : 48161.00
% Gps Status : $GPGGA,035348.00,2059.55364804,N,05034.93016495,E,5,15,0.7,199.466,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,87,79,65,66,88,78,,,,,,,1.6,0.7,1.4*24
% GNGST : $GNGST,035348.00,0.001,0.053,0.046,138.4,0.050,0.049,0.016*44
% GPZDA : $GPZDA,035348.01,25,11,2017,00,00*6D
% PTNL : $PTNL,GGK,035348.00,112517,2059.55364804,N,05034.93016495,E,12,15,1.6,EHT167.125,M*46
% TB : 17/11/25 03:53:36:380000 [14016380000 microsec]
然后我的代码得到的输出是(行转置为由 ; 分隔的列)
% VE464 V4.1.06;% Normal Acq ;% SL : 30391.00;% SN : 48097.00;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27;% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67;% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C;% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30385.00;% SN : 48161.00;% Gps Status : $GPGGA,035229.00,2059.52294297,N,05034.93435481,E,5,16,0.7,201.012,M,-32.341,M,1.0,0000*6;% Gps Status : $GPGGA,035229.00,2059.52294297,N,05034.93435481,E,5,16,0.7,201.012,M,-32.341,M,1.0,0000*6;% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.5,0.7,1.4*2F;% GPZDA : $GPZDA,035229.01,25,11,2017,00,00*6B;% PTNL : $PTNL,GGK,035229.00,112517,2059.52294297,N,05034.93435481,E,12,16,1.5,EHT168.672,M*43;% TB : 17/11/25 03:52:17:180000 [13937180000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30387.00;% SN : 48161.00;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F;% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63;% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F;% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30389.00;% SN : 48161.00;% Gps Status : $GPGGA,035348.00,2059.55364804,N,05034.93016495,E,5,15,0.7,199.466,M,-32.341,M,1.0,0000*;% Gps Status : $GPGGA,035348.00,2059.55364804,N,05034.93016495,E,5,15,0.7,199.466,M,-32.341,M,1.0,0000*;% GNGSA : $GNGSA,A,3,87,79,65,66,88,78,,,,,,,1.6,0.7,1.4*24;% GPZDA : $GPZDA,035348.01,25,11,2017,00,00*6D;% PTNL : $PTNL,GGK,035348.00,112517,2059.55364804,N,05034.93016495,E,12,15,1.6,EHT167.125,M*46;% TB : 17/11/25 03:53:36:380000 [14016380000 microsec]
在我对之前的输出进行一些处理后,我将得到(干净的输出):
% VE464 V4.1.06;% Normal Acq ;% SL : 30391.00;% SN : 48097.00;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6;% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27;% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67;% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C;% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06;% Normal Acq ;% SL : 30387.00;% SN : 48161.00;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*;% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F;% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63;% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F;% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
然后,使用以前的文件将喜欢从列转置为行,保持与原始文件相同的格式 (input.txt )
最终输出应该是这个:
% VE464 V4.1.06
% Normal Acq
% SL : 30391.00
% SN : 48097.00
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27
% GNGST : $GNGST,034403.00,0.001,0.053,0.046,127.2,0.049,0.050,0.017*44
% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67
% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C
% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30387.00
% SN : 48161.00
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F
% GNGST : $GNGST,035313.00,0.001,0.053,0.046,138.5,0.050,0.049,0.017*4A
% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63
% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F
% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
如果这可以改进并且更容易,并且使用最后一个(干净的输出)从列到行的转置,你会检查我的代码以从行到列转置吗?
你不需要太多的编程!
$ tr ';' '\n' <file
会完成这项工作,除非我错过了一些细节?!
% VE464 V4.1.06
% Normal Acq
% SL : 30391.00
% SN : 48097.00
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% Gps Status : $GPGGA,034403.00,2059.56495319,N,05034.47277356,E,5,15,0.7,207.283,M,-32.341,M,1.0,0000*6
% GNGSA : $GNGSA,A,3,87,72,65,66,88,81,78,,,,,,1.6,0.7,1.5*27
% GPZDA : $GPZDA,034403.02,25,11,2017,00,00*67
% PTNL : $PTNL,GGK,034403.00,112517,2059.56495319,N,05034.47277356,E,12,15,1.6,EHT174.943,M*4C
% TB : 17/11/25 03:43:51:732000 [13431732000 microsec]
% VE464 V4.1.06
% Normal Acq
% SL : 30387.00
% SN : 48161.00
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% Gps Status : $GPGGA,035313.00,2059.54233727,N,05034.93011171,E,5,14,0.7,199.952,M,-32.341,M,1.0,0000*
% GNGSA : $GNGSA,A,3,20,25,18,29,15,10,26,21,,,,,1.7,0.7,1.6*2F
% GPZDA : $GPZDA,035313.01,25,11,2017,00,00*63
% PTNL : $PTNL,GGK,035313.00,112517,2059.54233727,N,05034.93011171,E,12,14,1.7,EHT167.612,M*4F
% TB : 17/11/25 03:53:01:180000 [13981180000 microsec]
在记录之间添加一个空行
$ sed '$!G' file | tr ';' '\n'
假设记录之间有一个空行,转换为列可以简化为
$ awk -F'\n' -v RS= -v OFS=';' -v ORS='\n' '{=}1' file