gpt4 book ai didi

file - 在文件中搜索字符串并输出行号

转载 作者:行者123 更新时间:2023-12-01 00:58:56 24 4
gpt4 key购买 nike

awk '$0 ~ str{print b}{b=$0}' str="findme" path_to_file

有了这个我可以得到找到的字符串行之前的行。
如何打印它的行号?

最佳答案

使用NR获取当前行(记录)号:

awk '$0 ~ str{print NR-1 FS b}{b=$0}' str="findme" path_to_file

关于file - 在文件中搜索字符串并输出行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6161338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com