可是我想在它上面那一行的行首插入字符,不知道怎么弄

如图,我希望在每个标题前添加这个符号: ●nae6taiyie0T 写了:你要干嘛?
可以的话, 把你要匹配的文件帖出来, 看看你需要修改哪些字符?
代码: 全选
rss_cnBeta(){ # cnBeta RSS函数
RSS_cnBeta_tmp1=/tmp/rsscnBeta.tmp1
curl -s "http://cnbeta.feedsportal.com/c/34306/f/624776/index.rss" \
|sed -e 's/<title>/\n\n\n<title>/g' \
-e 's/<link>/\n<link>/g' \
-e 's/<description>/\n<description>/g' \
-e 's/\<\;/\n\<\;/g'\
|sed -e '/^\<\;/d' \
-e 's/<title>//g' \
-e 's/<\/title>//g' \
-e 's/<link>//g' \
-e 's/<\/link>//g' \
-e 's/<description>//g'\
|tail -n +8\
|sed -e 's/^http/----http/g' -e 's/&//g' >$RSS_cnBeta_tmp1
whiptail --title "cnBeta_RSS" --textbox $RSS_cnBeta_tmp1 0 0 && rm $RSS_cnBeta_tmp1
}
rss_cnBeta
trap 'rm /tmp/rss*;exit' 2
代码: 全选
$ cat a.awk
#!/usr/bin/gawk -f
BEGIN {
t = 0
}
{
if (match($0, /^http/) == 0) {
if (t != 0) {
print line
}
} else {
if (t != 0) {
print "prefix" line
}
}
line = $0
t = 1
}
END {
if (t == 1) {
print line
}
}
代码: 全选
$ cat text.txt
1 2 3 5
http://a.com
3 3
http://b.com
1
1
http://c.com
http://d.com
2
代码: 全选
$ ./a.awk text.txt
prefix1 2 3 5
http://a.com
prefix3 3
http://b.com
1
prefix1
prefixhttp://c.com
http://d.com
2
这主意好,简单方便,已经搞定YeLee 写了:覚得没有必要作后期替换吧,前期就把<title>匹配好的话,这样会简単很多的。
代码: 全选
rss_cnBeta(){ # cnBeta RSS函数
RSS_cnBeta_tmp1=/tmp/rsscnBeta.tmp1
curl -s "http://cnbeta.feedsportal.com/c/34306/f/624776/index.rss" |sed -e 's/<title>/\n\n\n●<title>/g' -e 's/<link>/\n<link>/g' -e 's/<description>/\n<description>/g' -e 's/\<\;/\n\<\;/g'|sed -e '/^\<\;/d' -e 's/<title>//g' -e 's/<\/title>//g' -e 's/<link>//g' -e 's/<\/link>//g' -e 's/<description>//g'|tail -n +8|sed -e 's/^http/----http/g' -e 's/&//g' >$RSS_cnBeta_tmp1
whiptail --title "cnBeta_RSS" --textbox $RSS_cnBeta_tmp1 0 0 && rm $RSS_cnBeta_tmp1
}
非常感谢前辈的教诲,菜鸟学习了astolia 写了:用awk吧代码: 全选
$ cat a.awk #!/usr/bin/gawk -f BEGIN { t = 0 } { if (match($0, /^http/) == 0) { if (t != 0) { print line } } else { if (t != 0) { print "prefix" line } } line = $0 t = 1 } END { if (t == 1) { print line } }
代码: 全选
$ cat text.txt 1 2 3 5 http://a.com 3 3 http://b.com 1 1 http://c.com http://d.com 2
代码: 全选
$ ./a.awk text.txt prefix1 2 3 5 http://a.com prefix3 3 http://b.com 1 prefix1 prefixhttp://c.com http://d.com 2
ubunbates 写了:sed -n '/^http/{x;s/^/你的符号/;x;};x;p;${x;p;}' 你的文件
解析不规则的文档,历来就没固定的方法。不应该用shell的简单方法去实现。youzhiyili 写了:ubunbates 写了:sed -n '/^http/{x;s/^/你的符号/;x;};x;p;${x;p;}' 你的文件![]()
可是,有一个小问题:文件头会多出一个空行,#!/bin/bash成了第二行
perl 怎么写?eexpress 写了:解析不规则的文档,历来就没固定的方法。不应该用shell的简单方法去实现。youzhiyili 写了:ubunbates 写了:sed -n '/^http/{x;s/^/你的符号/;x;};x;p;${x;p;}' 你的文件![]()
可是,有一个小问题:文件头会多出一个空行,#!/bin/bash成了第二行
多个空行不影响bash script的youzhiyili 写了:ubunbates 写了:sed -n '/^http/{x;s/^/你的符号/;x;};x;p;${x;p;}' 你的文件![]()
可是,有一个小问题:文件头会多出一个空行,#!/bin/bash成了第二行
前辈能不能讲解一下那个x和p是什么意思?ubunbates 写了:多个空行不影响bash script的youzhiyili 写了:ubunbates 写了:sed -n '/^http/{x;s/^/你的符号/;x;};x;p;${x;p;}' 你的文件![]()
可是,有一个小问题:文件头会多出一个空行,#!/bin/bash成了第二行
sed -n '/^http/{x;s/^/你的符号/;x;};1h;1!{x;p;};${x;p;}' 你的文件
p和x都是sed的命令, 与s一样.youzhiyili 写了:前辈能不能讲解一下那个x和p是什么意思?ubunbates 写了:多个空行不影响bash script的youzhiyili 写了:ubunbates 写了:sed -n '/^http/{x;s/^/你的符号/;x;};x;p;${x;p;}' 你的文件![]()
可是,有一个小问题:文件头会多出一个空行,#!/bin/bash成了第二行
sed -n '/^http/{x;s/^/你的符号/;x;};1h;1!{x;p;};${x;p;}' 你的文件
小弟是初学者,看不懂,先谢了