sed指令取代的問題 - Linux

Table of Contents

主要是分析lag
它的格式範例大致如下:

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
5FE7D17E9DC 57621 Mon Mar 28 10:24:56 [email protected]
(connect to aaa.ttt.org[xxx.xxx.xxx.xxx]: Connection refused)
[email protected]

現在要配合分析的程式把第三行的[email protected]
改成 remote [email protected]
remove和[email protected]中間只有要空白隔開即可多少不個空白不重要
試著利用grep和sed是能夠抓到我要的東西並修改
一開始我的寫法是
cat maillist | grep -v '^$' | grep -v '^[0-9A-Z]' | grep -v '(' | grep -v '^-'
| sed 's/^/remote/g'

但這樣寫是把我要的改的東西抓出來改好後輸出
和原本的需求不同
如果要直接寫進log不影響原本的格式
也就是log內容會是
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
5FE7D17E9DC 57621 Mon Mar 28 10:24:56 [email protected]
(connect to aaa.ttt.org[xxx.xxx.xxx.xxx]: Connection refused)
remote [email protected]
直接改掉應該要怎麼寫才好呢?


--

All Comments

Queena avatarQueena2011-04-07
重新導向,原po用過 > 了嗎?
Barb Cronin avatarBarb Cronin2011-04-12
重新導向的話只會輸出單純只有remove email的資料
Enid avatarEnid2011-04-14
也就是我要改的東西,但我是希望能在保留log原本的內容下
把我要的東西改掉