bash - 使用 Sed 读取目录中的最后 6 行

标签 bash unix ubuntu awk sed

我目前正在尝试使用 Sed 读取位于 http://www.ftp.ncep.noaa.gov/data/nccf/com/rtma/prod/rtma2p5.20140522/ 的 Web 目录中的最后(最近)6 行。 .

我目前正在尝试使用较旧的代码,但它似乎并没有让我走得太远......

wget -q -O - http://www.ftp.ncep.noaa.gov/data/nccf/com/rtma/prod/rtma2p5.20140522/ |
grep '<a href=' | tail -6 | sed -e 's/.*\(rtma2p5.t[0-9]*z.2dvaranl_ndfd.grb2\).*/\1/'

最佳答案

类(class)用马。

wget -q -O - http://www.ftp.ncep.noaa.gov/data/nccf/com/rtma/prod/rtma2p5.20140522/ \
  | tidy -asxml \
  | xmlstarlet sel -t -m '*//_:a[position() > last() - 6]' -v '@href' -n

关于bash - 使用 Sed 读取目录中的最后 6 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23818498/

相关文章:

regex - 如何在bash中用另一个字符串替换可变长度的重复字符串?

linux - 如何每隔 N 秒重复运行 bash 脚本?

linux - 如何使用 wget -i 下载和设置文件名?

linux - OpenSSL undefined symbol : EVP_mdc2, 版本 OPENSSL_1_1_0

ubuntu - 使用 ffmpeg ubuntu 连接两个文件时出错

bash - 尝试设置 $JAVA_HOME 时出错 - 错误 : JAVA_HOME is not set

python - Duo API Bash 调用

c - 首次输出到 stdout 后特定子进程的用户 CPU 时间

linux - kill(SIGSTOP) 是否在 kill() 返回时生效?

tensorflow - 无法在 Ubuntu 16.04 中配置 tensorflow 以使用 GPU 加速