AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1065190

Rafael Bankosegger's questions

Martin Hope
Rafael Bankosegger
Asked: 2019-09-29 09:21:28 +0800 CST

使用 sed 过滤 RSS 项目

  • 5

我想写一个脚本:

  • 接受一些 RSS-Feed URL 作为输入
  • 下载提要
  • 删除标记不匹配某些正则表达式<item> ...</item>的所有匹配项。title

下面的例子应该说明这一点。假设我们有一个包含这三个项目的 RSS 提要:

  • Project Foo - 让我们开始吧!
  • 完全不同的东西
  • Project Foo 的另一个更新

我只想保留标题中包含“Project Foo”的那些项目。

示例输入文件:

<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>My glorious newsfeed</title>
<description>...</description>
<link>...</link>
<language>...</language>
<pubDate>...</pubDate>

<item>
<title>Project Foo - Let's get started!</title>
<link>...</link>
<description>...</description>
<pubDate>...</pubDate>
</item>

<item>
<title>Something else entirely</title>
<link>...</link>
<description>...</description>
<pubDate>...</pubDate>
</item>

<item>
<title>Another update on Project Foo</title>
<link>...</link>
<description>...</description>
<pubDate>...</pubDate>
</item>

</channel>
</rss>

示例输出文件:

<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>My glorious newsfeed</title>
<description>...</description>
<link>...</link>
<language>...</language>
<pubDate>...</pubDate>

<item>
<title>Project Foo - Let's get started!</title>
<link>...</link>
<description>...</description>
<pubDate>...</pubDate>
</item>

<item>
<title>Another update on Project Foo</title>
<link>...</link>
<description>...</description>
<pubDate>...</pubDate>
</item>

</channel>
</rss>

如果可能的话,我想远离类似的东西,python并使用命令行工具来做到这一点。但我是一个使用sed等的大新手,需要一些帮助:)

这是我到目前为止所拥有的:

cat sample-feed.xml \
  | tr -d '\n' \
  | sed $'s/\<item\>/\\\n\<item\>/g;s/\<\/channel\><\/rss\>/\\\n\<\/channel\><\/rss\>/g' \
  | sed '/^\<item\>/ d'

首先,我删除所有换行符。然后,我添加换行符以将每个换行符带到<item>...</item>自己的行中。到目前为止的最后一个命令删除所有以 . 开头的行<item>。为了

结果是一个没有任何项目的有效 rss-feed:

<?xml version="1.0" encoding="iso-8859-1"?><rss version="2.0"><channel><title>My glorious newsfeed</title><description>...</description><link>...</link><language>...</language><pubDate>...</pubDate>    
</channel></rss>

为了使用 URL 而不是本地文件,我只需将其替换cat sample-feed.xml为curl -s <some url>.

但是仍然缺少的是对命令的修改sed '/^\<item\>/ d',它只删除以“Project Foo”开头<item>但不包含“Project Foo”的行。

所以,如果你能帮我弄清楚最后一行应该说什么,我会很高兴。另一方面,我确信有一种更优雅的方法可以做到这一点。从我所见sed,它非常强大,应该可以在一个sed命令中执行此操作。

期待你的回答:-)

sed curl
  • 1 个回答
  • 219 Views
Martin Hope
Rafael Bankosegger
Asked: 2019-07-21 02:48:41 +0800 CST

FFMPEG - 将 png 文件转换为视频文件

  • 11

我有大约 10k 个 PNG 文件,我想将它们转换成视频。

通过浏览互联网,我遇到了 ffmpeg 并选择运行以下命令:

ffmpeg -f image2 -r 25 -i img/* -vcodec libx264 -crf 22 video.mp4

首先,运行此命令会出现提示File 'img/00001.png' already exists. Overwrite ? [y/N],这对我来说似乎有点奇怪,因为据我所知,该命令不应该修改图像本身,只是创建一个新video.mp4文件?

反正我不想按y10k次,所以我备份了我的图片并修改了命令:

ffmpeg -f image2 -r 25 -i img/* -vcodec libx264 -crf 22 -y video.mp4

现在,该程序似乎可以很好地处理 254 张图像,但随后会抛出错误:

[png @ 0x7facf0503800] ff_frame_thread_encoder_init failed
Error initializing output stream 255:0 -- Error while opening encoder for output stream #255:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

如果它有用,我在此处添加了完整的日志文件。而且,为了更好地衡量,这里是我要转换的图像的示例。此外,这是臭名昭著的帧 255,程序在该帧上崩溃。

video command-line
  • 2 个回答
  • 10180 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve