嗨,我是新用的" sed"我需要使用bash脚本在特殊字符和空格之间显示文本。存在"类似"问题here但对我不起作用,因为我将在bash脚本中使用该变量。我需要帮助" sed"不是" perl"我本地没有index.html。我也在使用Linux。
这是我的变量:
output="$(wget -q http://software.opensuse.org/package/clementine -O - | sed -ne '/<p id="pkg-desc">/, /[.</p>]$/p')"
echo $ output
<p id="pkg-desc">Clementine is a modern music player and library organiser. Clementine is a port of Amarok 1.4, with some features rewritten to take advantage of Qt4.
还有关于如何在<p id="pkg-desc">
某些文字之间显示文字的其他替代选项。</p>
?或如何删除变量中的<p id="pkg-desc">
?
答案 0 :(得分:1)
这是gnu awk
版本
output=$(wget -q software.opensuse.org/package/clementine -O - | awk -v RS='<p id="pkg-desc">' -F"</p>" 'NR==2{print $1}')
echo "$output"
Clementine is a modern music player and library organiser. Clementine is a
port of Amarok 1.4, with some features rewritten to take advantage of Qt4.
Features:
* Search and play your local music library
* Listen to internet radio from Last.fm and SomaFM
* Edit tags on MP3 and OGG files, organise your music
* Cross-platform - works on Windows, Mac OS X and Linux
* Native desktop notifications on Linux (libnotify) and Mac OS X (Growl)
答案 1 :(得分:0)
output="$(wget -q software.opensuse.org/package/clementine -O - | sed -ne 's|<p id=\"pkg-desc\">\(.*\)</p>$|\1|p')"
"
,output="
|
作为sed分隔符而不是/
,因为字符串中存在此char以查找(更易于管理)s///
而不是因内部内容(仅限)打印//,//
的地址