在shell脚本中将数据的特定部分拆分为单行

时间:2012-07-20 05:48:52

标签: shell

我有一个文件,其中包含以下数据,它有几个MQ队列统计信息;

QueueName ='TEST1'
  CreateDate ='2009-10-30'
  CreateTime = '13 .45.40'
  QueueType =预定义的
  QueueDefinitionType = Local
  QMinDepth = 0
  QMaxDepth = 0
   QueueName ='TEST2'
  CreateDate ='2009-10-30'
  CreateTime = '13 .51.12'
  QueueType =预定义的
  QueueDefinitionType = Local
  QMinDepth = 0
  QMaxDepth = 6

我的输出应如下所示,每个队列的详细信息应显示在一个由空格分隔的单行中,

QueueName ='TEST1'CreateDate ='2009-10-30'CreateTime = '13 .45.40'QueueType = Predefined QueueDefinitionType = Local QMinDepth = 0 QMaxDepth = 0
  QueueName ='TEST2'CreateDate ='2009-10-30'CreateTime = '13 .51.12'QueueType = Predefined QueueDefinitionType = Local QMinDepth = 0 QMaxDepth = 6

1 个答案:

答案 0 :(得分:1)

http://www.gnu.org/software/gawk/manual/gawk.html#Output-Separators
“1”是打印所有内容的awk习语

awk -v ORS=' ' '/^QueueName=/{print "\n"} 1' foo.txt