亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 5301 | 回復(fù): 16
打印 上一主題 下一主題

sed如何做這個(gè)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-01-18 23:06 |只看該作者 |倒序?yàn)g覽
file1內(nèi)容:
[file]
path = /var/lib/mysql
comment = mysql server

[file]
path = /var/named
comment = bind data directory



file2內(nèi)容:
###
### here is a section
###


sed如何將file1編輯成如下?
###
### here is a section
###
[file]
path = /var/lib/mysql
comment = mysql server

###
### here is a section
###
[file]
path = /var/named
comment = bind data directory

論壇徽章:
2
射手座
日期:2014-10-10 15:59:4715-16賽季CBA聯(lián)賽之上海
日期:2016-03-03 10:27:14
2 [報(bào)告]
發(fā)表于 2011-01-19 00:17 |只看該作者
$ sed '/file/ {r file2
d}
/path/i\
[file] ' file1
###
### here is a section
###
[file]
path = /var/lib/mysql
comment = mysql server

###
### here is a section
###
[file]
path = /var/named
comment = bind data directory

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2011-01-19 00:24 |只看該作者
呵呵,不夠靈活

如果path是變化的,或者有多個(gè)path就不成了

論壇徽章:
2
射手座
日期:2014-10-10 15:59:4715-16賽季CBA聯(lián)賽之上海
日期:2016-03-03 10:27:14
4 [報(bào)告]
發(fā)表于 2011-01-19 00:34 |只看該作者
$ awk 'NR==FNR{a["[file]"]=$0"\n"a["[file]"] }NR>FNR{print a[$0]?a[$0]"\n"$00}' file2 file1
###
### here is a section
###

[file]
path = /var/lib/mysql
comment = mysql server

###
### here is a section
###

[file]
path = /var/named
comment = bind data directory

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2011-01-19 00:34 |只看該作者
tac file2 | sed '/^\[file\]$/r file1' | tac

論壇徽章:
2
射手座
日期:2014-10-10 15:59:4715-16賽季CBA聯(lián)賽之上海
日期:2016-03-03 10:27:14
6 [報(bào)告]
發(fā)表于 2011-01-19 00:41 |只看該作者
回復(fù) 3# __lxmxn__

try this:

$ sed '/file/ {r file2
a [file]
d}' file1
###
### here is a section
###
[file]
path = /var/lib/mysql
comment = mysql server

###
### here is a section
###
[file]
path = /var/named
comment = bind data directory

論壇徽章:
84
每日論壇發(fā)貼之星
日期:2015-12-29 06:20:00每日論壇發(fā)貼之星
日期:2016-01-16 06:20:00每周論壇發(fā)貼之星
日期:2016-01-17 22:22:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-20 06:20:00每日論壇發(fā)貼之星
日期:2016-01-20 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-21 06:20:00每日論壇發(fā)貼之星
日期:2016-01-21 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-23 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-31 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-16 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-16 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-14 06:20:00
7 [報(bào)告]
發(fā)表于 2011-01-19 00:53 |只看該作者
回復(fù) 1# __lxmxn__


sed '/\[file/ {:l /.*\(\n\n\|$\)/! {N; b l;}; s//###\n### xxx\n###\n&/; }'  file1

論壇徽章:
84
每日論壇發(fā)貼之星
日期:2015-12-29 06:20:00每日論壇發(fā)貼之星
日期:2016-01-16 06:20:00每周論壇發(fā)貼之星
日期:2016-01-17 22:22:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-20 06:20:00每日論壇發(fā)貼之星
日期:2016-01-20 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-21 06:20:00每日論壇發(fā)貼之星
日期:2016-01-21 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-23 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-31 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-16 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-16 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-14 06:20:00
8 [報(bào)告]
發(fā)表于 2011-01-19 01:58 |只看該作者
本帖最后由 yjh777 于 2011-01-19 02:36 編輯

sed "s/\[file/`   sed  ':l; N; $! b l; s/\\n/\\\\n/g'  file2  `\n&/" file1



-------------------------------------------------------------------------------------------------------
注意 ``  $() 區(qū)別, 直接$()就可以, 用``時(shí)還得將\再轉(zhuǎn)義}
sed 's/\[file/'"$(   sed  ':l; N; $! b l; s/\n/\\n/g'  file2   )"'\n&/' file1

headStr=$(sed  ':l; N; $! b l; s/\n/\\n/g'  file2)
sed "s/\[file/${headStr}\\n&/" file1

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2011-01-19 10:40 |只看該作者
嗯,多謝 yjh777 兄~

感覺可以利用sed的hold space和pattern space來做到,但最終嘗試失敗。

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2011-01-20 18:06 |只看該作者
  1. sed '/\[file\]/s//###\n### here is a section\n###\n&/' urfile
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP