bash

How can I duplicate an existing object within a JSON array using jq?

戏子无情 提交于 2021-02-20 19:17:12
问题 I have the following geojson file: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "LINE": "RED", "STATION": "Harvard" }, "geometry": { "type": "Point", "coordinates": [-71.118906072378209, 42.37402923068516] } }, { "type": "Feature", "properties": { "LINE": "RED", "STATION": "Ashmont" }, "geometry": { "type": "Point", "coordinates": [-71.063430144389983, 42.283883546225319] } } ] } I would like to append the second object within the "features" array to the

How can I duplicate an existing object within a JSON array using jq?

痞子三分冷 提交于 2021-02-20 19:16:55
问题 I have the following geojson file: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "LINE": "RED", "STATION": "Harvard" }, "geometry": { "type": "Point", "coordinates": [-71.118906072378209, 42.37402923068516] } }, { "type": "Feature", "properties": { "LINE": "RED", "STATION": "Ashmont" }, "geometry": { "type": "Point", "coordinates": [-71.063430144389983, 42.283883546225319] } } ] } I would like to append the second object within the "features" array to the

Remove specific words from sentences in bash?

笑着哭i 提交于 2021-02-20 19:14:12
问题 I want to remove negative words form sentence using bash script . The negative words that i meant it : [dull,boring,annoying,bad] My file text text.txt contains this sentence : These dull boring cards are part of a chaotic board game ,and bad for people I'm using this script array=( dull boring annoying bad ) for i in "${array[@]}" do cat $p | sed -e 's/\<$i\>//g' done < my_text.txt But I got the following wrong result: These boring cards are part of a chaotic board game ,and bad for people

why cant I redirect the output from sed to a file

隐身守侯 提交于 2021-02-20 18:51:12
问题 I am trying to run the following command ./someprogram | tee /dev/tty | sed 's/^.\{2\}//' > output_file But the file is always blank when I go to check it. If I remove > output_file from the end of the command, I am able to see the output from sed without any issues. Is there any way that I can redirect the output from sed in this command to a file? 回答1: Remove output-buffering from sed command using the -u flag and make sure what you want to log isn't on stderr -u, --unbuffered load minimal

How to handle space in filename in bash script?

别来无恙 提交于 2021-02-20 16:55:44
问题 I want to automate rsyncing, and tried the following code: TARGET="/media/USB\ DISK/Backup/" rsync -av --delete ~/Data ${TARGET} but the execution results in the following error: rsync: link_stat "/media/USB\" failed: No such file or directory (2) rsync: mkdir "/home/DISK/BACKUP" failed: No such file or directory (2) because of the 'space' in the target filename. However, when I echo the command I can use that to run on the shell directly. How to do it correctly (which brackets, with

sh和bash之间的区别

浪子不回头ぞ 提交于 2021-02-20 16:49:57
问题: When writing shell programs, we often use /bin/sh and /bin/bash . 在编写shell程序时,我们经常使用 /bin/sh 和 /bin/bash 。 I usually use bash , but I don't know what's the difference between them. 我通常使用 bash ,但是我不知道它们之间有什么区别。 What's main difference between bash and sh ? bash 和 sh 之间的主要区别是什么? What do we need to be aware of when programming in bash and sh ? 在使用 bash 和 sh 编程时,我们需要注意什么? 解决方案: 参考一: https://stackoom.com/question/O1PU/sh和bash之间的区别 参考二: https://oldbug.net/q/O1PU/Difference-between-sh-and-bash 来源: oschina 链接: https://my.oschina.net/u/4438370/blog/4492883

Shell编程基础

怎甘沉沦 提交于 2021-02-20 13:46:34
注: 本文说的都是bash(Bourne Again Shell),是sh(Bourne Shell)的扩展 扩展名不会影响脚本执行,见名知意就行,一般情况下扩展名是sh Shell注释:以 # 开头的行就是注释,会被解释器忽略,但是sh里面没有多行注释,只能每行加一个# 从Ubuntu 6.10开始,默认使用dash,需要手动执行命令将dash改为bash, 至于bash和dash的区别,详见 https://blog.csdn.net/hshl1214/article/details/51122663 命令:sudo dpkg-reconfigure dash 然后在出现的页面中选择NO,之后就可以正常运行脚本了 运行Shell脚本的两种方法: 作为可执行程序 让脚本文件具有可执行权限 chmod +x file 加上执行权限,否则会提示无执行权限。 ./文件名 注意,例要执行test.sh脚本,一定要写成 ./test.sh,而不是 test.sh,运行其它二进制的程序也一样,直接写 test.sh,linux 系统会去 PATH 里寻找有没有叫 test.sh 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 test.sh 是会找不到命令的,要用 ./test.sh 告诉系统说

Zookeeper集群搭建

纵饮孤独 提交于 2021-02-20 13:29:03
1、环境 centos7 zookeeper-3.5.2 三台虚拟机:master、slaves1、slaves2 2、将zookeeper安装包先上传到master的/opt/softWare/zookeeper目录下并解压和重命名 3、进入conf目录将zoo_sample.cfg文件重命名为zoo.cfg并添加如下配置: #数据目录. 可以是任意目录,其中的dataDir目录和dataLogDir需要提前建立好 #注意 应该谨慎地选择日志存放的位置,使用专用的日志存储设备能够大大地提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会在很大程度上影响系统的性能。 dataDir=/opt/softWare/zookeeper/data/zookeeper #log目录, 同样可以是任意目录. 如果没有设置该参数, 将使用和dataDir相同的设置,其中的dataDir目录和dataLogDir需要提前建立好 #注意 应该谨慎地选择日志存放的位置,使用专用的日志存储设备能够大大地提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会在很大程度上影响系统的性能。 dataLogDir=/opt/softWare/zookeeper/logs/zookeeper #在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server.

How to grep a term from S3 and output object name

谁说我不能喝 提交于 2021-02-20 04:49:07
问题 I need to grep a term over thousands of files in S3, and list those file names in some output file. I'm quite new using cli, so I've been testing both on my local, and in a small subset in s3. So far I've got this: aws s3 cp s3://mybucket/path/to/file.csv - | grep -iln searchterm > output.txt The problem with this is with the hyphen. Since I'm copying over to standard output, the -l switch in grep returns (standard input) instead of file.csv My desired output is file.csv Eventually, I'll need