- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有类似于以下内容的 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<OnlineCommentary>
<doc docid="cnn_210085_comment002" articleURL="http://www.cnn.com/News.asp?NewsID=210085" date="10/07/2010" time="00:21" subtitle="Is Justin Bieber getting special treatment?" author="Zorro75">
<seg id="1"> They are the same thing. Let's shoot them both. </seg>
</doc>
<doc docid="cnn_210092_comment004" articleURL="http://www.cnn.com/News.asp?NewsID=210092" date="06/04/2010" time="17:07" subtitle="Dear Chicago, we love you despite it all" author="MRL1313">
<seg id="1"> We can't wait for you to move back either. </seg>
<seg id="2"> You seem quite uptight. </seg>
<seg id="3"> Does your wife (who is also your sister) not give it up any more? </seg>
</doc>
</OnlineCommentary>
我想在此文件上执行命令以仅提取开始标记之间的contnet <seg ...>
和结束标记 </seg>
我试过了:
sed -n 's:.*<seg id="1">\(.*\)</seg>.*:\1:p' XML-file.xml > output.txt
我的问题如下:
-- 如何打印所有 <seg id="*">
??我的命令只打印第一个标签的内容(<seg id="*">
)
-- 是否有一种方法可以用来制作例如 <seg id="1">
, <seg id="2">
, <seg id="3">
打印在同一行,而标签只包含 <seg id="1">
打印在单独的行??
最佳答案
打印所有<seg id=>
(每行一个)包括 <seg
sed -n 's:.*\(<seg id="[0-9]\{1,\}">.*</seg>\).*:\1:p' XML-file.xml > output.txt
全部打印在 1 行上,分隔 ,
.使用保持缓冲区而不是打印,最后调用缓冲区,用 ,
替换新行(并删除开始 ,
由于追加操作),并打印结果
sed -n '\:.*\(<seg id="[0-9]\{1,\}">.*</seg>\).*: { s//\1/
H
}
$ {g
s/\n/,/g;s/^,//
p
}' XML-file.xml > output.txt
现在,@Choroba 使用适当的 XML 工具的建议非常好,您可以最大限度地降低处理不需要的文件数据的风险。
关于xml - 使用 sed 在两个 XML 标签之间提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25930230/
我需要一些有关 Sed 的帮助。我在 Windows 和 Mac OSX 上使用它。我需要 Sed 添加一个 每 4 行,在第一个 之后找到,并在 上停止这样做 我就是找不到办法做到这一点。每
我是一个管理很多网站的轮换团队的一员,我们继承了一个网站的一些特别糟糕的代码,我们正在彻底重新设计该网站。非常可怕的是,开发服务器上有一些链接将您带到实时服务器和旧域以及许多其他可怕的事情。 我一直在
我正在尝试在脚本中运行以下表达式以查找设备并在html文件中更改与该设备关联的字段之一。 sed -e "s/$OLDTEST/$TESTING/" -e "s/$CURRENTVALU/$NEWST
我正在尝试使用 sed 删除所有出现的 #ifdef _WIN32 #endif #ifdef 和 #endif 之间存在的所有内容都是空行。我使用 sed 的经验有限,我已经阅读了一些关于多行功能的
以下命令是什么意思: sed -e '/SUBCKT\ REDBK128S4_LC/,/ENDS/ d' $1 什么,代表? 最佳答案 如果指定两个地址,则指定执行命令的行范围。在您的 sed表达
我需要使用sed注释匹配行和其后的4行的帮助。 在文本文件中。 我的文本文件是这样的: [myprocess-a] property1=1 property2=2 property3=3 proper
我想要一个sed命令来完成以下任务: $ sed s'/:/ /g' sed s'/=/ /g' 也就是说,我想写 sed s'// /g' 并用空格替换=和:。 最佳答案 sed s'/[:=]/
我想在大文件中每隔30行插入一个字符串。我正在使用mini-sed,它不支持〜(波浪号)范围运算符。我正在寻找仅sed的解决方案。 最佳答案 该线程是如何使事情过于复杂的另一个示例。应该这样做: se
有人可以帮我吗? grep " 287 " file.txt | grep "HI" | sed -i 's/HIS/HID/g' sed: no input files 也尝试过 xargs gre
这个问题已经有答案了: How can I replace each newline (\n) with a space using sed? (43 个回答) 已关闭2 年前。 如何使用 sed 命
我们需要屏蔽信用卡号。屏蔽除最后 4 位数字以外的所有数字。我正在尝试使用 SED。由于信用卡号长度从 12 位到 19 位不等,我正在尝试编写正则表达式。以下代码将收到字符串。如果它包含形式为“CA
例如: sed 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' abc.txt 's@' 、 '(' 、 '\?' 、'&' 和 '@' 等含义是什么? 如何找到最合适
我们有一个进程可以使用包含 sed 的文件更改管道输入的命令。 我需要用变量值替换输入中的占位符,例如在一个 -e我可以运行的命令类型; $ echo "Today is XX" | sed -e "
这个问题在这里已经有了答案: Using different delimiters in sed commands and range addresses (3 个答案) 关闭1 年前。 我想问 2
是的,我搜索了该网站,但我认为我没有看到任何东西可以专门解决我无法克服的非常(我想很简单)的问题。 我正在上 Linux 类(class),有人问我这个问题: Use the sed command
我有一个看起来像这样的文件路径列表 abc/def/ghi/jl/r1/r2 abc/def/ghi/jl/r9/r11 abc/nyc/ghi/jl/r3/r4/r5 abc/nyc/ghi/jl/
我在这个文件中有这个文本: test.php $databases = array ( 'default' => array ( 'default' => array (
让我们考虑一个包含以下语句的 SQL 文件作为输入(即 myTable.sql): EXECUTE IMMEDIATE 'CREATE OR REPLACE PUBLIC SYNONYM ' || m
好的,谷歌搜索几分钟后,这似乎是在每行输出前加上 sed 前缀的常规方法 但是我得到一个我不明白的错误。 这是什么意思,我该如何解决? $ sed 's/^/#/' test.txt sed: -e
我有以下文件列表: r1 r2 10 r11 r99 我正在尝试替换 ls 输出中文件名中 r 之后的所有数字 我要找的结果: rA rA rA rA rA 使用下面的 sed 命令我可以匹配
我是一名优秀的程序员,十分优秀!