- 論壇徽章:
- 145
|
本帖最后由 jason680 于 2014-11-28 15:11 編輯
回復(fù) 1# boris369
Here is an example for you
Note: modify the "..." by youself
$ cat html
<li>...1</li>
<li>...2</li>
<li>...3</li>
<li>...4</li>
<li>...5</li>
<li>...6</li>
<li>...7</li>
$ ./sp1000.sh
html: 網(wǎng)站地圖1.html
html: 網(wǎng)站地圖2.html
$ grep "." 網(wǎng)站地圖*.html
網(wǎng)站地圖1.html:<html ...>
網(wǎng)站地圖1.html:<head>
網(wǎng)站地圖1.html:<title>網(wǎng)站地圖1</title>
網(wǎng)站地圖1.html:</head>
網(wǎng)站地圖1.html:<body>
網(wǎng)站地圖1.html:...
網(wǎng)站地圖1.html:<li>...1</li>
網(wǎng)站地圖1.html:<li>...2</li>
網(wǎng)站地圖1.html:<li>...3</li>
網(wǎng)站地圖1.html:<li>...4</li>
網(wǎng)站地圖1.html:...
網(wǎng)站地圖1.html:</html>
網(wǎng)站地圖2.html:<html ...>
網(wǎng)站地圖2.html:<head>
網(wǎng)站地圖2.html:<title>網(wǎng)站地圖2</title>
網(wǎng)站地圖2.html:</head>
網(wǎng)站地圖2.html:<body>
網(wǎng)站地圖2.html:...
網(wǎng)站地圖2.html:<li>...5</li>
網(wǎng)站地圖2.html:<li>...6</li>
網(wǎng)站地圖2.html:<li>...7</li>
網(wǎng)站地圖2.html:...
網(wǎng)站地圖2.html:</html>
$ cat sp1000.sh
head="<html ...>\n<head>"
body="<body>\n..."
tail="...\n</html>"
awk -vs=4 -vhead="$head" -vbody="$body" -vtail="$tail" '
BEGIN{ OFS="\n" }
function p(n){
file = "網(wǎng)站地圖" int(NR/s+n)
title= "<title>" file "</title>\n</head>"
print head, title, body, t, tail > file".html"
print "html: " file".html"
t=""
}
{ t=t$0"\n" }
NR%s==0{ p(0) }
END { if(t!="")p(1) }
' html
|
|