Вы используете записи в /etc/resolvconf/resolv.conf.d/
с именами head
, base
или tail
(в зависимости от того, где в resolv.conf
вы хотите видеть ваши записи). Из man resolvconf
:
The dynamically generated resolver configuration file always starts
with the contents of /etc/resolvconf/resolv.conf.d/head and ends with
the contents of /etc/resolvconf/resolv.conf.d/tail. Between head and
tail the libc script inserts dynamic nameserver information compiled
from, first, information provided for configured interfaces; second,
static information from /etc/resolvconf/resolv.conf.d/base.
Просто поместите ваши записи в base
и запустите resolvconf -u
.
jq
раствор:
jq -s '{ attributes: map(.attributes[0]) }' file*.json
-s
(--slurp
)-вместо запуска фильтра для каждого объекта JSON во входных данных, считывайте весь входной поток в большой массив и запускайте фильтр только один раз. Пример вывода:
{
"attributes": [
{
"name": "Node",
"value": "test"
},
{
"name": "version",
"value": "11.1"
}
]
}
В отличие от решения Романа Перехреста , это позволит объединить целевое поле без переделки всего объекта:
jq -s '.[0].attributes = [.[].attributes | add] |.[0]' file*.json
Это возвращает весь первый файл json с .attributes
из всех остальных, объединенных вместе.
Использовать jsonmerge
>>> base = {
... "foo": 1,
... "bar": [ "one" ],
... }
>>> head = {
... "bar": [ "two" ],
... "baz": "Hello, world!"
... }
>>> from pprint import pprint
>>> from jsonmerge import merge
>>> result = merge(base, head)
>>> pprint(result, width=40)
{'bar': ['two'],
'baz': 'Hello, world!',
'foo': 1}
Еще один вариант jq
, без чавканья, но с inputs
иreduce
jq -n 'reduce inputs as $in ({}; reduce ($in|keys_unsorted)[] as $k (.;
.[$k] += $in[$k]))' file1 file2