AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-16792

Philip Kirkbride's questions

Martin Hope
Philip Kirkbride
Asked: 2020-03-02 07:14:12 +0800 CST

将 JSON 数组转换为 CSV

  • 6

我正在寻找将 JSON 转换为 CSV 的解决方案。似乎大多数解决方案都希望 JSON 是单个对象而不是对象数组。

我从这里尝试过的所有解决方案似乎都与我的输入不同,这些输入来自curling this site。

jq当输入是数组而不是对象时,如何使用或其他工具将 JSON 转换为 CSV 。

[
  {
    "id": "4",
    "link": "https://pressbooks.online.ucf.edu/amnatgov/",
    "metadata": {
      "@context": "http://schema.org",
      "@type": "Book",
      "name": "American Government",
      "inLanguage": "en",
      "copyrightYear": "2016",
      "disambiguatingDescription": "The content of this textbook has been developed and arranged to provide a logical progression from the fundamental principles of institutional design at the founding, to avenues of political participation, to thorough coverage of the political structures that constitute American government. The book builds upon what students have already learned and emphasizes connections between topics as well as between theory and applications. The goal of each section is to enable students not just to recognize concepts, but to work with them in ways that will be useful in later courses, future careers, and as engaged citizens. ",
      "image": "https://pressbooks.online.ucf.edu/app/uploads/sites/4/2020/01/American-Government.png",
      "isBasedOn": "https://ucf-dev.pb.unizin.org/pos2041",
      "author": [
        {
          "@type": "Person",
          "name": "OpenStax"
        }
      ],
      "datePublished": "2016-01-06",
      "copyrightHolder": {
        "@type": "Organization",
        "name": "cnxamgov"
      },
      "license": {
        "@type": "CreativeWork",
        "url": "https://creativecommons.org/licenses/by/4.0/",
        "name": "CC BY (Attribution)"
      }
    },
    "_links": {
      "api": [
        {
          "href": "https://pressbooks.online.ucf.edu/amnatgov/wp-json/"
        }
      ],
      "metadata": [
        {
          "href": "https://pressbooks.online.ucf.edu/amnatgov/wp-json/pressbooks/v2/metadata"
        }
      ],
      "self": [
        {
          "href": "https://pressbooks.online.ucf.edu/wp-json/pressbooks/v2/books/4"
        }
      ]
    }
  }
]

所需格式:

id, link, context, type, name, inLanguage, image, author_type, author_name, license_type, license_url, license_name
json csv
  • 2 个回答
  • 6446 Views
Martin Hope
Philip Kirkbride
Asked: 2020-01-27 08:39:56 +0800 CST

设置 $PS3 无效

  • 0

我正在尝试更改PS3,我希望以下脚本会在运行时显示新值:

select i in red blue green exit
do
  case $i in
    red) echo "Red";;
    blue) echo "Blue";;
    green) echo "Green";;
    exit) exit;;
  esac
done

然后我更改 PS3 值。

PS3=">"

但是当我运行脚本时,#?会使用默认值。

在此处输入图像描述

不知道我错过了什么,可以使用哪些值有限制吗?

bash terminal
  • 1 个回答
  • 35 Views
Martin Hope
Philip Kirkbride
Asked: 2019-12-22 14:04:16 +0800 CST

用更少的管道显示图像元数据?

  • 3

我正在观看有关更少管道的视频,并且制造商能够打开图像文件并取回一堆元数据:

在此处输入图像描述

我的系统似乎有更少的管道,我可以查看 PDF 和压缩文件less,但打开图像时我没有取回任何元数据。我只得到如下一行。

在此处输入图像描述

我注意到它ffmpeg在底部说的视频,我确实安装了它。是否可以更改某种设置less以显示图像的更多详细信息?

用于检查较少管道的命令已安装:

echo $LESSOPEN

用于打开图像的命令:

less image.jpg
less images
  • 1 个回答
  • 270 Views
Martin Hope
Philip Kirkbride
Asked: 2019-12-20 22:05:35 +0800 CST

缺少 Posix 实用程序?

  • 0

我一直认为 posix 标准中定义的任何东西都会出现在最常见的 Linux 发行版上。

然而,当我查看 posix 标准中哪些实用程序是标准的时,我发现这个页面有一个很长的列表。

在尝试了一些我没有听说过的东西之后,我很快注意到很多东西似乎没有安装在我的系统上。

也许这些实用程序只是名称不同?例如c99,我的系统上没有,但我有cc我认为可以编译为c99.

我尝试过但似乎不在我的系统上的其他实用程序:

  • what
  • uux
  • qalter
  • renice
  • sact

我只尝试了一些看起来不熟悉的命令,但我猜我的系统上没有更多的命令。

这些是可选的实用程序吗?

linux posix
  • 1 个回答
  • 209 Views
Martin Hope
Philip Kirkbride
Asked: 2019-11-22 19:32:10 +0800 CST

哪些流行的程序使用 GNU Readline?

  • 2

我正在阅读有关 Bash 中的键绑定的信息。它们似乎基于 Emacs,但提供了切换到vi基于 Emacs 的能力。

您可以set -o vi在您.bashrc的 Bash 中执行此操作,但我看到还有一个选项可以编辑.inputrc通过添加以下行调用的文件:

set editing-mode vi

通过编辑.inputrc而不是.bashrc使用 GNU Readline 库的所有程序将切换到vi键绑定。

我可能不会切换绑定,因为我现在使用 Emacs 绑定并且我喜欢使用默认值,但这个事实让我对 GNU Readline 和.inputrc. 哪些流行的实用程序和程序使用了这个库?

keyboard-shortcuts inputrc
  • 1 个回答
  • 447 Views
Martin Hope
Philip Kirkbride
Asked: 2019-11-22 12:30:40 +0800 CST

将 JSON 数组转换为 Bash

  • 1

我正在使用JQ从测验数据库中获取一些 JSON,并且我想解析结果。我正在尝试将结果数组保存在 Bash 中,如下所示,但格式是 JavaScript/Python 中使用的带有方括号而不是 Bash 样式的格式。

quiz=$(curl -s https://opentdb.com/api.php?amount=3)
answers=$(echo $quiz | jq '[ .results][0][0].incorrect_answers')
correct=$(echo $quiz | jq '[ .results][0][0].correct_answer')
answers+=( $correct )

答案的示例如下:

[ "Excitement", "Aggression", "Exhaustion" ]

由于格式错误,永远不会将正确答案推送到数组中。

如何转换上述格式的数组,以便在我的脚本中将其解释为数组。

输出示例curl (这不是硬编码,问题和答案每次都不同):

{
  "response_code": 0,
  "results": [
    {
      "category": "Entertainment: Television",
      "type": "multiple",
      "difficulty": "easy",
      "question": "Which company has exclusive rights to air episodes of the "The Grand Tour"?",
      "correct_answer": "Amazon",
      "incorrect_answers": [
        "Netflix",
        "BBC",
        "CCTV"
      ]
    },
    {
      "category": "Celebrities",
      "type": "multiple",
      "difficulty": "medium",
      "question": "How much weight did Chris Pratt lose for his role as Star-Lord in "Guardians of the Galaxy"?",
      "correct_answer": "60 lbs",
      "incorrect_answers": [
        "30 lbs",
        "50 lbs",
        "70 lbs"
      ]
    },
    {
      "category": "Animals",
      "type": "boolean",
      "difficulty": "easy",
      "question": "The Killer Whale is considered a type of dolphin.",
      "correct_answer": "True",
      "incorrect_answers": [
        "False"
      ]
    }
  ]
}
bash shell-script
  • 5 个回答
  • 8047 Views
Martin Hope
Philip Kirkbride
Asked: 2019-02-14 23:11:16 +0800 CST

Grep 删除 0 但不是 0.2 的行?

  • 13

我有一个文件,其内容类似于以下文件。

0
0
0.2
0
0
0
0

我需要用一个零删除所有行。
我正在考虑使用grep -v "0",但这也删除了包含 0.2 的行。我看到我可以使用该-w选项,但这似乎也不起作用。

如何删除仅包含一个 0 的所有行并保留所有以 0 开头的行?

grep
  • 8 个回答
  • 6633 Views
Martin Hope
Philip Kirkbride
Asked: 2019-01-06 16:06:53 +0800 CST

解析所有特定长度的字符串?

  • 2

我已经导出了 10 年的电子邮件存档,非常大。

我想解析任何长度为 64 个字符的字符串的所有文本,以搜索比特币私钥。

如何解析字符中一定长度的字符串?

text-processing files
  • 4 个回答
  • 2552 Views
Martin Hope
Philip Kirkbride
Asked: 2018-12-31 16:44:16 +0800 CST

jq获取嵌套对象的属性

  • 7

我有以下结构(此处为完整文件示例):

{
  {
    "weather": [
      {
        "advertiser": "Worldwide Forecasts",
        "notificationText": "Weather - Check the Weather Now - Weather",
        "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
        "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
        "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"
      },
      {
        "advertiser": "Worldwide Forecasts",
        "notificationText": "Weather - Check the Weather Now - Weather",
        "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
        "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
        "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"
      }
    ]
  }
}

与weather示例类似的几个类别。

我想用来jq获取所有值的列表,notificationURL以便我得到所有广告商的 URL 列表。

我最初认为我可以做类似的事情:

cat file.json | jq .[].[].notificationURL

但这不起作用。

jq
  • 1 个回答
  • 18035 Views
Martin Hope
Philip Kirkbride
Asked: 2018-12-10 18:26:09 +0800 CST

使用 minimodem 转换以 RTTY 45.45 波特编码的声音

  • 3

我下载了一个以 RTTY 45.45 波特(链接视频的 mp3 输出)编码的文件。我不确定最终输出应该是音频还是文本。

我还安装minimodem了我正在阅读的可以将数据转换为音频的选项--tx和输出--rx。

例如将图片转换为音频并返回:

cat pic.jpg | minimodem --tx 9600 -f audio.wave

minimodem --rx 9600 -f audio.wave > pic2.jpg

我尝试了以下两个命令,一个期望音频输出,另一个期望文本:

minimodem --rx rtty -f youtube.mp3 > out.mp3

minimodem --rx rtty -f youtube.mp3 > out.txt

这些似乎都不起作用。

谁能告诉我如何解码这个故事?

audio modem
  • 1 个回答
  • 1602 Views
Martin Hope
Philip Kirkbride
Asked: 2018-11-13 14:21:33 +0800 CST

在 groff 中嵌入 ascii 图?

  • 1

我有 groff 文件来生成格式的 pdf:

.TL
Article title
.AU
Author name
.AI
Publication title
.SH
.LP
First paragraph
.PP
More paragraphs

然后我正在运行groff -ms a.ms -T pdf > a.pdf以生成pdf。我喜欢 groff 如何使格式化变得容易,但我想知道是否可以包含 ascii 图。

例如以下:

 +-------------------------+             +-----------------+
 |                         |             |                 |
 |      Hello              |             |                 |
 |                         +-------------+                 |
 |                         |             |                 |
 +-------------------------+             +-----------------+

如果作为普通段落输入变成:

在此处输入图像描述

无论如何我可以在 groff 中插入一个部分来保留空格,以便可以使用这些图表?

看手册groff_ms我看到:

.PS 和 .PE 表示要由 pic 预处理器处理的图形。您可以手动创建 pic 文件,使用 Web 上提供的 AT&T pic 手册作为参考,或使用 xfig 等图形程序。

但这似乎只接受图片语言标记。

无论如何我可以将 assci 图纸插入 groff 吗?

text-formatting ascii
  • 2 个回答
  • 931 Views
Martin Hope
Philip Kirkbride
Asked: 2018-02-09 16:21:08 +0800 CST

后台子进程是否与父进程一起死亡?

  • 7

我有一个调用其他几个子脚本的脚本。它后来被杀死了,这似乎杀死了所有的子脚本。

在大多数情况下,这就是我想要的。但是有一两个案例我不想让孩子死去。

我想我记得能够通过&在调用脚本时使用背景来阻止这种情况的发生。

谁能证实这一点?

bash process
  • 1 个回答
  • 6823 Views
Martin Hope
Philip Kirkbride
Asked: 2018-01-27 07:13:54 +0800 CST

查找哪些包控制网络接口?

  • 1

我有一个在启动时运行的 debian 包。

我正在使用新贵,我想我需要向新贵配置添加依赖项:

start on someProgram

我不确定是哪个程序,但我没有使用network-manager它,它已被禁用。我正在做这样的事情:

ethernet=$(ifconfig -a | grep Ethernet | grep ^e | cut -d' ' -f1)
wifi=$(ifconfig -a | grep wl | cut -d' ' -f1)
ping -I $ethernet -c 1 8.8.8.8 \
  || ping -I $wifi -c 1 8.8.8.8 \
  || echo "not online"

问题是ifconfig并不总是显示$wifi界面,因为程序在启动过程中打开得太早了。

ping -I $ethernet -c 1 8.8.8.8当它应该成功时也会失败。

如果我这样做sleep 30那么ping它工作正常。

有谁知道我应该等待什么包才能让它按预期工作?

我在嵌入式设备上使用 Ubuntu 14.04。

3.0.36+ #16 SMP PREEMPT Tue Oct 31 19:17:57 EDT 2017 armv7l armv7l armv7l GNU/Linux

我以为我有一个答案:

我发现可以直接引用网络接口而不是包:

start on (local-filesystems and net-device-up IFACE!=lo)

我仍然想针对我的情况稍微改进一下。

因为我宁愿等待 wlan 而不是 eth 但我不确定我是否可以使用像这样的通配符:IFACE=wlan*

但似乎这并没有等待接口可用,ifconfig而是等待该接口具有活动的 Internet 连接。

networking debian
  • 1 个回答
  • 55 Views
Martin Hope
Philip Kirkbride
Asked: 2018-01-23 07:09:37 +0800 CST

访问 || 另一侧的标准错误?

  • 2

我想做类似的事情:

command || log $error_from_last_command

有没有办法像管道一样使用||和访问?stderr

command我的目的是处理来自, using的错误消息log,但前提是command失败。我正在阅读标记的副本,但我不知道如何将其应用于我的情况。

bash
  • 2 个回答
  • 72 Views
Martin Hope
Philip Kirkbride
Asked: 2018-01-13 11:30:06 +0800 CST

骆驼大写下划线[重复]

  • 4
这个问题在这里已经有了答案:
将下划线转换为 PascalCase,即 UpperCamelCase 8 个答案
3年前关闭。

如何将下划线分隔的单词转换为“camelCase”?这是我正在尝试的:

echo "remote_available_packages" | sed -r 's/([a-z]+)_([a-z])([a-z]+)/\1\U\2\L\3/'

但它会在remoteAvailable_packages不更改pin的情况下返回packages。

sed
  • 3 个回答
  • 4865 Views
Martin Hope
Philip Kirkbride
Asked: 2018-01-13 06:03:36 +0800 CST

无法 grep apt-get 的输出

  • 1

如果我运行:

apt-get install --dry-run 2klic-embedded-gui=*-master

我得到:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
2klic-embedded-gui is already the newest version.
Selected version '3.1.0-8-master' (all 2klic-updates:2klic-updates [all]) for '2klic-embedded-gui'
0 upgraded, 0 newly installed, 0 to remove and 182 not upgraded.

我正在努力:

apt-get install --dry-run 2klic-embedded-gui=*-master 2>&1 | grep gui

这不会返回任何东西。所以我尝试stdbuf:

stdbuf -oL -eL apt-get install --dry-run 2klic-embedded-gui=*-master 2>&1 | grep gui

这将返回第 4 行,但我期待第 4 行和第 5 行。

为什么第 5 行不被重定向到grep?

grep buffer
  • 1 个回答
  • 320 Views
Martin Hope
Philip Kirkbride
Asked: 2017-12-14 17:56:46 +0800 CST

使用 || awk ENVIRON 更换后

  • 2

我正在使用带有变量的 awk 来根据时间戳剪切日志文件:

LAST_LOG=$last_log awk 'index($0, ENVIRON["LAST_LOG"]) {y=1;next};y' $log_file ;

如果日期仍然存在于日志文件中,它可以工作,但如果日志文件已存档并替换为新文件,awk则会失败。

cat $log_file如果awk失败,我想退回到:

LAST_LOG=$last_log awk 'index($0, ENVIRON["LAST_LOG"]) {y=1;next};y' $log_file ; \
  || cat $log_file

但是这个语法返回syntax error near unexpected token ||.

上面的行不是我可以使用&&或||之后使用的正常功能吗?

bash awk
  • 2 个回答
  • 1070 Views
Martin Hope
Philip Kirkbride
Asked: 2017-12-14 13:54:16 +0800 CST

抑制子shell中的错误?

  • 4

我想在某个点之后抑制我的子外壳中的错误。

我编写了脚本来演示这种情况:

worked=false
(echo Starting subshell process \
    && echo If this executes process is considered success \
    && false \
    && echo run if possible, but not an error if failed) \
  && worked=true

echo $worked

我想向外壳报告该过程有效。

我还考虑将工作变量放在子shell中:

    && echo This works process worked: \
    && worked=true \
    && false \
    && echo run if possible, but not an error if failed)

但这也不起作用,因为在子外壳中设置变量不会影响主脚本。

bash
  • 4 个回答
  • 1474 Views
Martin Hope
Philip Kirkbride
Asked: 2017-12-09 11:03:50 +0800 CST

dh_usrlocal: ... 不是目录

  • 4

我正在使用 Makefile 设置来创建一个 debian 包:

.PHONY: package
package: $(PACKAGE_TARGETS)

build/%.changes: ../%.changes
        mkdir -p build
        for f in `<$< awk 'BEGIN { files = 0; } { if (files) print $$5; } /^Files:/ { files = 1; }'`; do \
            test -f build/$$f || mv ../$$f build/; \
        done
        mv $< $@

../%.changes:
        dpkg-buildpackage -rfakeroot -b -uc

在我做了一个非常小的提交之前,一切都在构建中正常工作。其中添加了一个可执行文件在/src/bin/app-cli. 然后在 debian 安装文件中引用该可执行文件debian/app.install:

src/bin/app-cli usr/local/bin

出于某种原因,进行该更改会导致构建系统生成错误:

dh_usrlocal: debian/app/usr/local/bin/app-cli is not a directory
rmdir: failed to remove 'debian/app/usr/local/bin': Directory not empty
dh_usrlocal: rmdir debian/app/usr/local/bin returned exit code 1
make[1]: *** [binary] Error 1
make[1]: Leaving directory `/var/lib/jenkins/data/workspace/app-VBJPWWOTACEEMDGNNWMFS4QU6K4EPG5PJRESMEIZPZL4GAUCKWVQ'
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2
make: *** [../app_0.0.1-13-master_amd64.changes] Error 2

有谁知道这个新文件被 Debian Helper 视为目录?

debian package-management
  • 2 个回答
  • 4022 Views
Martin Hope
Philip Kirkbride
Asked: 2017-12-09 07:41:40 +0800 CST

Makefile中的引用函数?

  • -1

我正在修改 aMakefile以添加一个命令,该命令将用于更新和编译依赖项。

我已经有make clean命令工作了。现在我试图让它在我运行任何其他make命令之前运行。

我正在尝试添加all: clean,但它似乎不起作用:

.PHONY: all
all: clean

.PHONY: clean
clean:
        rm -rf build

update-dep:
        mkdir -p build/package_name \
          && # do stuff here

运行任何其他功能时如何运行干净?

make
  • 1 个回答
  • 144 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve