• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

我在Bash使用尾部文件的最后非空行

用户头像
it1352
帮助1

问题说明

我如何使用的最后一个非空行下的Bash shell?

How do I get the last non-empty line using tail under Bash shell?

例如, my_file.txt适用是这样的:

您好结果
  HOLA结果
  卓悦结果
  (空行)结果
  (空行)

hello
hola
bonjour
(empty line)
(empty line)

显然,如果我这样做尾-n 1 my_file.txt适用我会得到一个空行。在我来说,我想获得卓悦。我该怎么做呢?

Obviously, if I do tail -n 1 my_file.txt I will get an empty line. In my case I want to get bonjour. How do I do that?

正确答案

#1

您可以使用awk的:

awk '/./{line=$0} END{print line}' my_file.txt

此溶液具有只使用一个工具的优点。

This solution has the advantage of using just one tool.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfjece
系列文章
更多 icon
同类精品
更多 icon
继续加载