使用 sed 删除所有文本
格式:
[Headword]{}"UC(icl>restriction)"(Attributes);(gloss)
testme.txt 文件有 2 行
[testme] {} "acetify" (V,lnk,CJNCT,AJ-V,VINT,VOO,VOO-CHNG,TMP,Vo) <H,0,0>;
[newtest] {} "acid-fast" (ADJ,DES,QUAL,TTSM) <H,0,0>;
预期输出是这样的:
testme = acetify
newtest = acid-fast
到目前为止我所取得的成果是:
cat testme.txt | sed 's/[//g'| sed 's/]//g' | sed 's/{}/=/g' | sed 's/{}/=/g' | sed 's/\"//'
testme = acetify" (V,lnk,CJNCT,AJ-V,VINT,VOO,VOO-CHNG,TMP,Vo) <H,0,0>;
newtest = acid-fast" (ADJ,DES,QUAL,TTSM) <H,0,0>;
如何删除从第二个 " 到行尾的所有文本?
Format:
[Headword]{}"UC(icl>restriction)"(Attributes);(gloss)
The testme.txt file has 2 lines
[testme] {} "acetify" (V,lnk,CJNCT,AJ-V,VINT,VOO,VOO-CHNG,TMP,Vo) <H,0,0>;
[newtest] {} "acid-fast" (ADJ,DES,QUAL,TTSM) <H,0,0>;
The expected output is this:
testme = acetify
newtest = acid-fast
What I have achieved so far is:
cat testme.txt | sed 's/[//g' | sed 's/]//g' | sed 's/{}/=/g' | sed 's/\"//'
testme = acetify" (V,lnk,CJNCT,AJ-V,VINT,VOO,VOO-CHNG,TMP,Vo) <H,0,0>;
newtest = acid-fast" (ADJ,DES,QUAL,TTSM) <H,0,0>;
How do I remove all the text from the second " to the end of the line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
删除双引号空格开括号
" (
:Remove everything after the doublequote-space-openparenthesis
" (
:使用
awk
整个过程可能会更快一些:The whole process might be a little quicker with
awk
:这就是使用 awk 而不是所有那些
sed
命令的方法,这是不必要的。您想要的是字段 1 和字段 3。使用gsub()
删除引号和括号this is how you do it with awk instead of all those
sed
commands, which is unnecessary. what you want is field 1 and field 3. usegsub()
to remove the quotes and brackets对
sed
的多次调用的整个序列可以替换为:Your whole sequence of multiple calls to
sed
can be replaced by: