bash

Remove duplicate filename extensions

こ雲淡風輕ζ 提交于 2021-02-08 03:49:48
问题 I have thousands of files named something like filename.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz I am using the find command like this find . -name "*.gz*" to locate these files and either use -exec or pipe to xargs and have some magic command to clean this mess, so that I end up with filename.gz Someone please help me come up with this magic command that would remove the unneeded instances of .gz . I had tried experimenting with sed 's/\.gz//' and sed 's/(\.gz)//' but they do not seem to work (or to

Remove duplicate filename extensions

倖福魔咒の 提交于 2021-02-08 03:49:37
问题 I have thousands of files named something like filename.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz I am using the find command like this find . -name "*.gz*" to locate these files and either use -exec or pipe to xargs and have some magic command to clean this mess, so that I end up with filename.gz Someone please help me come up with this magic command that would remove the unneeded instances of .gz . I had tried experimenting with sed 's/\.gz//' and sed 's/(\.gz)//' but they do not seem to work (or to

Bash: Count total number of keys in an associative array?

a 夏天 提交于 2021-02-08 02:17:19
问题 Consider the associative array below: declare -A shapingTimes shapingTimes=([0-start]=15 [0-stop]=21 [0-anotherkey]=foo) shapingTimes+=([1-start]=4 [1-stop]=6 [1-anotherkey]=bar) shapingTimes+=([2-start]=9 [2-stop]=11 [2-anotherkey]=blah) Is there a way to find the total number of keys used per entry in an array? (Is this per 'index' in an array?) For example, how to count: [start], [stop], [anotherkey] as = 3 keys? At the moment I'm using the hardcoded value (3) from this code I found (as

Interweave two files bash script

浪尽此生 提交于 2021-02-08 02:15:29
问题 I am trying to interweave two files that contain one sentence per line. I double spaced ( sed G ) the first file and I would like to incorporate the content of the second file into those empty lines. How can I interweave both files so that the 1st line of file B goes below the 1st line in file A, the 2nd line of file B below the 2nd line of file A, until it reaches the end ? Example: [line number|sentence number|sentence] 1 1 fileA 2 3 2 fileA 4 5 3 fileA 6 7 4 fileA Expected result: 1 1

Interweave two files bash script

依然范特西╮ 提交于 2021-02-08 02:11:22
问题 I am trying to interweave two files that contain one sentence per line. I double spaced ( sed G ) the first file and I would like to incorporate the content of the second file into those empty lines. How can I interweave both files so that the 1st line of file B goes below the 1st line in file A, the 2nd line of file B below the 2nd line of file A, until it reaches the end ? Example: [line number|sentence number|sentence] 1 1 fileA 2 3 2 fileA 4 5 3 fileA 6 7 4 fileA Expected result: 1 1

Loop through JSON object using jq

半城伤御伤魂 提交于 2021-02-07 23:23:13
问题 This is what my JSON array of objects looks like: [ { "Description": "Description 1", "OutputKey": "OutputKey 1", "OutputValue": "OutputValue 1" }, { "Description": "Description 2", "OutputKey": "OutputKey 2", "OutputValue": "OutputValue 2" }, { "Description": "Description 3", "OutputKey": "OutputKey 3", "OutputValue": "OutputValue 3" }, { "Description": "Description 4", "OutputKey": "OutputKey 4", "OutputValue": "OutputValue 4" }, { "Description": "Description 5", "OutputKey": "OutputKey 5",

Why rvm needs login shell?

余生长醉 提交于 2021-02-07 22:46:17
问题 As far as I know, rvm is a set of bash scripts. Why it need login shells? Which property which only exists in login shells is necessary for rvm? Related post: rvm installation not working: “RVM is not a function” 回答1: Your RVM config line ( [[ -s "$HOME/.rvm ... ) likely located is in .profile , which is only read when your bash is on login-shell mode. There are other config files that are read in other modes as well, like .bashrc when the shell is interactive, but non-login or file defined

Rsync backup one source directory and check agains multiple directories

给你一囗甜甜゛ 提交于 2021-02-07 20:36:57
问题 I am trying to copy(rsync) the "sdir" directory to tdir directories depending on what day it is. I want one full copy to mon directory, tues only what changed, wed only what changed, etc. but I am not getting the results I need. Refer to actual command I ran: [jesse@localhost test]$ tree . ├── sdir │ ├── file1 │ ├── file2 │ ├── file3 │ ├── file4 │ └── file5 └── tdir ├── fri ├── mon │ ├── file1 │ └── file2 ├── thu ├── tue │ └── file3 └── wed ├── file3 ├── file4 └── file5 7 directories, 11

How to get exit code of remote command through ssh

夙愿已清 提交于 2021-02-07 20:28:57
问题 I am running a script from remote machine via ssh: ssh 'some_cmd;my_script' Now, I want to store exit status of shell script on my local machine. How can I do it? 回答1: Assuming nothing goes wrong with ssh itself, its exit status is the exit status of the last command executed on the remote host. (If something does go wrong, its exit status is 255.) $ ssh remotehost exit 13 $ echo $? 13 来源: https://stackoverflow.com/questions/37701143/how-to-get-exit-code-of-remote-command-through-ssh

Examine Bash variables with dynamic names

最后都变了- 提交于 2021-02-07 20:23:53
问题 I'm trying to read from Bash variables for which I know name suffixes, but I want to iterate through the prefixes. I give an example below: var1_name="variable1" var1_size="2" var2_name="variable2" var2_size="3" vars=(var1 var2) for v in "${vars[@]}" do echo $v_name echo $v_size done and I'd want the output to look like follows: variable1 2 variable2 3 Is there any to do this with Bash? I have tried with eval and associative arrays, but I still can't find a way to examine an already defined