第一次比赛后删除行

编程入门 行业动态 更新时间:2024-10-27 01:32:21
本文介绍了第一次比赛后删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要删除包含单词"fox"的第一行之后的所有行

I need to remove all lines after the first line that contains the word "fox"

例如,以下输入文件"in.txt"

Say for example for the following input file "in.txt"

The quick brown fox jumps over the lazy dog the second fox is hunting

结果将是

The quick brown fox jumps

我更喜欢用awk或sed编写的脚本,但是其他任何命令行工具都很好,例如perl或php或python等.

I prefer a script made in awk or sed but any other command line tools are good, like perl or php or python etc.

出于搜索目的,我将添加以下行:

For searching purposes I will add this line:

出现后删除行

以后

我在Windows中使用gnuwin32工具,而我能找到的解决方案是:

I am using gnuwin32 tools in Windows, and the solution I could find was this one:

grep -m1 -n fox in.txt | cut -f1 -d":" > var.txt set /p MyNumber=<var.txt head -%MyNumber% in.txt > out.txt

但是,我正在寻找一种更短且可移植的解决方案(此解决方案包含Wi​​ndows特定的命令"set/p"

However, I am looking for a solution that is shorter and that is portable (this one contains Windows specific command "set /p"

类似的问题:

  • 如何删除模式最后一次出现后的所有行吗?

如何在保留比赛之前删除行它吗?

在与sed比赛之前删除所有行

如何使用sed在遇到模式[[ERROR] -17-12-2015]之前从第一行开始删除行,直到行之间?

如何删除字符串的第一次出现和最后一次出现之后的所有行?

推荐答案

awk '{print} /fox/{exit}' file

使用GNU sed:

sed '0,/fox/!d' file

sed -n '0,/fox/p' file

更多推荐

第一次比赛后删除行

本文发布于:2023-11-23 04:29:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:赛后

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!