分类: 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