bash

How to loop over jq unique array in bash?

≯℡__Kan透↙ 提交于 2021-02-10 17:51:28
问题 I'm trying to loop over unique names and commit messages from a github json object. However when there are spaces in the arrays bash will treat them as individual array items #!/usr/bin/env bash commits='[ { "author": { "email": "email@example.com", "name": "Chris", "username": "chris" }, "committer": { "email": "email@example.com", "name": "Chris", "username": "chris" }, "message": "commit message 1" }, { "author": { "email": "email@example.com", "name": "John", "username": "jdoe" },

How to loop over jq unique array in bash?

心已入冬 提交于 2021-02-10 17:49:20
问题 I'm trying to loop over unique names and commit messages from a github json object. However when there are spaces in the arrays bash will treat them as individual array items #!/usr/bin/env bash commits='[ { "author": { "email": "email@example.com", "name": "Chris", "username": "chris" }, "committer": { "email": "email@example.com", "name": "Chris", "username": "chris" }, "message": "commit message 1" }, { "author": { "email": "email@example.com", "name": "John", "username": "jdoe" },

Count files, except the hidden files [duplicate]

眉间皱痕 提交于 2021-02-10 17:33:24
问题 This question already has answers here : Why does find . -not -name “.*” not exclude hidden files? (2 answers) How to count all files inside a folder, its subfolder and all . The count should not include folder count [closed] (2 answers) Closed 2 years ago . I'm trying to count all the files from the current folder and each of it's sub-folders. find . -type f \(! -iname ".*" \) -print 回答1: You can use this find command: find -type f ! -regex ".*/\.[^/]+$" | wc -l It will find all files in the

Extract values from a property file using bash

泄露秘密 提交于 2021-02-10 16:56:14
问题 I have a variable which contains key/values separated by space: echo $PROPERTY server_geo=BOS db.jdbc_url=jdbc\:mysql\://mysql-test.com\:3306/db02 db.name=db02 db.hostname=/mysql-test.com datasource.class.xa=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource server_uid=BOS_mysql57 hibernate33.dialect=org.hibernate.dialect.MySQL5InnoDBDialect hibernate.connection.username=db02 server_labels=mysql57,mysql5,mysql db.jdbc_class=com.mysql.jdbc.Driver db.schema=db02 hibernate.connection.driver_class

Extract values from a property file using bash

╄→гoц情女王★ 提交于 2021-02-10 16:55:41
问题 I have a variable which contains key/values separated by space: echo $PROPERTY server_geo=BOS db.jdbc_url=jdbc\:mysql\://mysql-test.com\:3306/db02 db.name=db02 db.hostname=/mysql-test.com datasource.class.xa=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource server_uid=BOS_mysql57 hibernate33.dialect=org.hibernate.dialect.MySQL5InnoDBDialect hibernate.connection.username=db02 server_labels=mysql57,mysql5,mysql db.jdbc_class=com.mysql.jdbc.Driver db.schema=db02 hibernate.connection.driver_class

How to add a bash array into the fields of a JSON array using jq?

大兔子大兔子 提交于 2021-02-10 15:52:07
问题 I currently have the following JSON output from echo $items | jq : { "Family_Name": "Type 1", "Quantity_On_Hand": "335" } { "Family_Name": "Type 2", "Quantity_On_Hand": "215" } { "Family_Name": "Type 9", "Quantity_On_Hand": "159" } { "Family_Name": "Type 4", "Quantity_On_Hand": "500" } I also have a bash array colors of the same size looking like "Blue" "Red" "Green" "Blue" How can I use jq so that I get something like { "Family_Name": "Type 1", "Quantity_On_Hand": "335", "Colors": "Blue" } {

How to add a bash array into the fields of a JSON array using jq?

回眸只為那壹抹淺笑 提交于 2021-02-10 15:46:58
问题 I currently have the following JSON output from echo $items | jq : { "Family_Name": "Type 1", "Quantity_On_Hand": "335" } { "Family_Name": "Type 2", "Quantity_On_Hand": "215" } { "Family_Name": "Type 9", "Quantity_On_Hand": "159" } { "Family_Name": "Type 4", "Quantity_On_Hand": "500" } I also have a bash array colors of the same size looking like "Blue" "Red" "Green" "Blue" How can I use jq so that I get something like { "Family_Name": "Type 1", "Quantity_On_Hand": "335", "Colors": "Blue" } {

Bash - How to run code whenever USB device is connected

China☆狼群 提交于 2021-02-10 15:43:40
问题 I am writing a bash script to automatically detect when my USB keyboard is plugged into my laptop (running Ubuntu 14), so I can change the keyboard layout automatically. Here is my code so far (I got it from another post on Stack Overflow so I'm not 100% sure how it works) #!/bin/bash setxkbmap es for dev in /sys/bus/usb/devices/ *-*:* do if [ -f $dev/bInterfaceClass ] then if [[ "$(cat $dev/bInterfaceClass)" == "03" && "$(cat $dev/bInterfaceProtocol)" == "01" ]] then setxkbmap gb fi fi done

Prepend timestamp to each line received from stdin

旧城冷巷雨未停 提交于 2021-02-10 15:40:22
问题 Hi there I'm trying to create logs using bash but the time I'm getting is wrong. I'm running this in background. # log code here before executing curl script log "Yay I was started" curl https://example.com/process | sed "s/^/$(date -u) /" >> /path/to/logs.log & The time set after processing curl is the time it was executed not the time after I got the response. I need to get the time after the response. Here's the sample output (Wrong response) Fri Aug 21 01:43:12 UTC 2020 Yay I was started

Prepend timestamp to each line received from stdin

给你一囗甜甜゛ 提交于 2021-02-10 15:39:43
问题 Hi there I'm trying to create logs using bash but the time I'm getting is wrong. I'm running this in background. # log code here before executing curl script log "Yay I was started" curl https://example.com/process | sed "s/^/$(date -u) /" >> /path/to/logs.log & The time set after processing curl is the time it was executed not the time after I got the response. I need to get the time after the response. Here's the sample output (Wrong response) Fri Aug 21 01:43:12 UTC 2020 Yay I was started