Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1270066
  • 博文数量: 554
  • 博客积分: 10425
  • 博客等级: 上将
  • 技术积分: 7555
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 09:49
文章分类

全部博文(554)

文章存档

2012年(1)

2011年(1)

2009年(8)

2008年(544)

分类: LINUX

2008-10-22 14:02:57

1。合并行,四行为一行。
awk '{if (NR%4==0){print $0} else {printf"%s ",$0}}' filename

2.删除相同行。
awk '!a[$0]++' file

3.用grep 取行中的固定值。

2008-10-10 14:43:32.315 - CpSpotRateInfo:[FxPriceId=20081008MKPD000002310426,CurrencyPair=USD/ZAR,CounterpartyId=MOCK,MessageTime=2008-10-10 14:43:32:312,JST,usualable=true,inManualStatus0,inEmgerencyStatus0,--Bid:Band [0] PriceId=S00300000000048,Rate=5.8915,Tradable=true;ContractCurrency=USD,LowerAmount=0,UpperAmount=2000000.0;CounterCurrency=ZAR,LowerAmount=0,UpperAmount=11783000;--Ask:Band [0] PriceId=S00300000000048,Rate=5.8917,Tradable=true;ContractCurrency=USD,LowerAmount=0,UpperAmount=2000000.0;CounterCurrency=ZAR,LowerAmount=0,UpperAmount=11783400;]

想取CurrencyPair=USD/ZAR

则 grep -Eo "CurrencyPair=......."

 

4.以某行为分界线用sed 合并行

CurrencyPair=GBP/CAD
LowerAmount=0
LowerAmount=0
LowerAmount=0
LowerAmount=0
CurrencyPair=GBP/USD
LowerAmount=0
LowerAmount=0
LowerAmount=0
LowerAmount=0
CurrencyPair=CAD/CHF
LowerAmount=0
LowerAmount=0
LowerAmount=0
LowerAmount=0
CurrencyPair=USD/ZAR
LowerAmount=0
LowerAmount=0

sed ':a;$!N;/\nCurrencyPair=/!s/\n/ /;ta;P;D' ufile

5.sed 合并两个关键字之间的行

HH

aa

bb

cc

dd

//

 

 

sed '/HH/{n;:a;N;/\/\//{s/ //g;b};s/\n//;ta}' urfile


 

阅读(1566) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~