解析 FIX 消息以进行进一步分析

解析 FIX 消息以进行进一步分析

我目前正在尝试解析我的 FIX 消息以获取显示货币(tag55)和价格(tag133)的 2 列,但使用“awk”时遇到困难,因为消息的所需部分似乎没有分成几列(以粗体显示)供你参考)。关于如何实现这一目标有什么想法吗?

FIX log example:
03:55:16.128 incoming           20180528-07:55:16.015           8587130         11891           8587030         S                  **8=FIX.4.29=013535=S49=IUAT2Feed56=FixServer50=IUAT2Feed_Offers34=858713052=20180528-07:55:16.015117=055=NOK/SEK7225=7133=1.0735135=2100000010=159**
03:55:16.128 incoming           20180528-07:55:16.015           8587131         11891           8587030         S                  **8=FIX.4.29=013435=S49=IUAT2Feed56=FixServer50=IUAT2Feed_Offers34=858713152=20180528-07:55:16.015117=055=USD/CNH7225=2133=6.3872135=300000010=110**

期望的输出:

NOK/SEK 1.0735
USD/CNH 6.3872

答案1

  perl -F= -pale '$_ = sprintf "%.7s %.4f", @F[-5,-3]'   fix.log

¶ 怎么运行的 :

 °  split each line as it comes on equal to sign. Store the split values in the array @F

 °  counting from the end of the array @F, the last but 4th  and last but 2nd fields are what we need.

 °  we require the 7 chars and accuracy upto 4 digits.

 °  stuff these in $_ and -p option auto prints it. 

答案2

以下内容awk可能会对您有所帮助。

awk -F"=" '{sub(/[0-9]+/,"",$(NF-4));print $(NF-4),$(NF-2)+0}' OFMT="%.05g"  Input_file

答案3

使用 awk 你可以这样做:

$ awk -F= '{for (i=1;i<=NF;i++) if($i ~ "NOK" || $i ~ "USD"){print $i,$(i+2)}}' input_file | awk '{gsub(/[0-9]/,"",$1)}1'
NOK/SEK 1.0735135
USD/CNH 6.3872135

相关内容