大数据处理(AWK)

时间:2015-08-11 07:37:11

标签: awk

我已经过滤了一个主要文件中的一些重要数据,例如图1中的那个,我最后得到了一个如图2所示。事情就是我用多个命令完成了这个,例如:

awk '{gsub("ndn.InterestLifetime=2000&ndn.Nonce", ""); print $1,$2,$3,$10,$11,$12}'
awk 'NF'
awk -F':' -v OFS='=' '{print $1, $2, $3, $4, $5, $6, $7, $8}'
awk '{if($6 =="") {print $1, $2, $3, $4, $5, $6="0", $7} else {print $1, $2, $3, $4, $5, $6, $7}}'
awk '{if($4 == "D" ) {print $1, $2, $3, $4, $5, $6, $7="\t""\t""1024", $8} else{print $1, $2, $3, $4, $5, $6, $7="\t""24", $8}}'
awk '{printf "%-10s %-10s %-10s %-10s %-10s %-16s %-10s\n", $1, $2, $3, $4, $5, $6, $7}'

所有这些命令我在控制台中逐个运行以获得最终输出,但此时我有大约100个文件要分析。

有没有办法将所有这些命令合并到一个脚本中,只需一步即可从图1到图2?

谢谢!

注意:有些字符我不得不手动将其删除,因为当应用gsub时,它也删除了不应删除的字符。 图1:

   + 0 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Interest (I: /prefix/%FE%00?ndn.InterestLifetime=2000&ndn.Nonce=3506978425)
   - 0 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Interest (I: /prefix/%FE%00?ndn.InterestLifetime=2000&ndn.Nonce=3506978425)
   + 0.0020224 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Interest (I: /prefix/%FE%00?ndn.InterestLifetime=2000&ndn.Nonce=3506978425)
   - 0.0020224 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Interest (I: /prefix/%FE%00?ndn.InterestLifetime=2000&ndn.Nonce=3506978425)
   r 0.0020224 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Interest (I: /prefix/%FE%00?ndn.InterestLifetime=2000&ndn.Nonce=3506978425)
   r 0.0040448 /NodeList/2/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Interest (I: /prefix/%FE%00?ndn.InterestLifetime=2000&ndn.Nonce=3506978425)
   + 0.0040448 /NodeList/2/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Data (D: Name: /prefix/%FE%00

    MetaInfo: ContentType: 0, FreshnessPeriod: 0 milliseconds
   Content: (size: 1024)
   Signature: (type: 255, value_length: 0)
   )

    - 0.0040448 /NodeList/2/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: NDN (0x0077)) ns3::ndn::Data (D: Name: /prefix/%FE%00
   MetaInfo: ContentType: 0, FreshnessPeriod: 0 milliseconds
   Content: (size: 1024)
   Signature: (type: 255, value_length: 0)
   )

`图2:

   +          0          /NodeList/10/ I          /%FE%00    3911074054       24        
   -          0          /NodeList/10/ I          /%FE%00    3911074054       24        
   +          0.01       /NodeList/10/ I          /%FE%01    2369863103       24        
   -          0.01       /NodeList/10/ I          /%FE%01    2369863103       24        
   +          0.02       /NodeList/10/ I          /%FE%02    1645723821       24        
   -          0.02       /NodeList/10/ I          /%FE%02    1645723821       24        
   +          0.03       /NodeList/10/ I          /%FE%03    3521946681       24        
   -          0.03       /NodeList/10/ I          /%FE%03    3521946681       24        
   +          0.04       /NodeList/10/ I          /%FE%04    471669802        24        
   -          0.04       /NodeList/10/ I          /%FE%04    471669802        24        
   +          0.05       /NodeList/10/ I          /%FE%05    2273949020       24        
   -          0.05       /NodeList/10/ I          /%FE%05    2273949020       24        
   +          0.06       /NodeList/10/ I          /%FE%06    2325138250       24        
   -          0.06       /NodeList/10/ I          /%FE%06    2325138250       24        
   +          0.07       /NodeList/10/ I          /%FE%07    3740802279       24        
   -          0.07       /NodeList/10/ I          /%FE%07    3740802279       24        
   +          0.08       /NodeList/10/ I          /%FE%08    745982218        24        
   -          0.08       /NodeList/10/ I          /%FE%08    745982218        24        
   +          0.09       /NodeList/10/ I          /%FE%09    2174891134       24        
   -          0.09       /NodeList/10/ I          /%FE%09    2174891134`       24        

0 个答案:

没有答案