bash

run command until successful n times bash

假如想象 提交于 2021-02-10 20:51:02
问题 I want to run a command n number of times if it returns unsuccessful I have started with the below loop until find . -type f -exec md5sum {} \; do <something > done I want to run the about n times before it goes continues to the next file Not sure how I can continue from here. I have tried using the return variable $? and looping using this but had no luck Also how could I use the above loop or what is proposed here to put the output of the find into a variable thanks Let me make this abit

Merging word counts with Bash and Unix

本秂侑毒 提交于 2021-02-10 19:52:28
问题 I made a Bash script that extracts words from a text file with grep and sed and then sorts them with sort and counts the repetitions with wc , then sort again by frequency. The example output looks like this: 12 the 7 code 7 with 7 add 5 quite 3 do 3 well 1 quick 1 can 1 pick 1 easy Now I'd like to merge all words with the same frequency into one line, like this: 12 the 7 code with add 5 quite 3 do well 1 quick can pick easy Is there any way to do that with Bash and standard Unix toolset? Or

Merging word counts with Bash and Unix

旧巷老猫 提交于 2021-02-10 19:51:53
问题 I made a Bash script that extracts words from a text file with grep and sed and then sorts them with sort and counts the repetitions with wc , then sort again by frequency. The example output looks like this: 12 the 7 code 7 with 7 add 5 quite 3 do 3 well 1 quick 1 can 1 pick 1 easy Now I'd like to merge all words with the same frequency into one line, like this: 12 the 7 code with add 5 quite 3 do well 1 quick can pick easy Is there any way to do that with Bash and standard Unix toolset? Or

Create string with trailing spaces in Bash

僤鯓⒐⒋嵵緔 提交于 2021-02-10 19:50:41
问题 I'd like to loop over an associative array and print out the key / value pairs in a nice way. Therefore I'd like to indent the values in such a way, that they all start at the same position behind their respective keys. Here's an example: declare -A my_array my_array["k 1"]="value one" my_array["key two"]="value two" for key in "${!my_array[@]}"; do echo "$key: ${my_array[$key]}" done The output is k 1: value one key two: value two The output I'd like to have would be (for arbitrary key

I cannot run conda command /activate environment on ubuntu?

爱⌒轻易说出口 提交于 2021-02-10 19:41:36
问题 I have installed anaconda in ubuntu and am facing a problem with anaconda. I was running the following command in a conda environment: 271 pip install --user -r requirements.txt 272 cd .. 273 conda install ipython jupyter 274 conda install jupyter 275 python 276 sudo apt-get install python-vtk python-wxgtk2.6 python-setuptools python-numpy python-configobj 277 sudo apt-get install python-vtk python-wxgtk2.8 python-setuptools python-numpy python-configobj 278 conda install -c anaconda mayavi=

aws cli s3 sync: how to exclude multiple files

為{幸葍}努か 提交于 2021-02-10 18:48:55
问题 So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket. #!/bin/bash # deploy to s3 function deploy(){ aws s3 rm s3://bucketname --profile Administrator --recursive aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' -

Change variable named in argument to bash function [duplicate]

女生的网名这么多〃 提交于 2021-02-10 18:48:43
问题 This question already has answers here : Dynamic variable names in Bash (16 answers) How to use a variable's value as another variable's name in bash [duplicate] (6 answers) Closed 3 years ago . In my bash scripts, I often prompt users for y/n answers. Since I often use this several times in a single script, I'd like to have a function that checks if the user input is some variant of Yes / No, and then cleans this answer to "y" or "n". Something like this: yesno(){ temp="" if [[ "$1" =~ ^([Yy

subtract columns from 2 files and output to new files

放肆的年华 提交于 2021-02-10 18:38:55
问题 I have 2 files in below formats. File1_Stored.txt ABC:100, 83 ABC:84, 53 ABC:14, 1222 File2_Stored.txt ABC:100 , 83 ABC:84 , 1553 ABC:524 , 2626 I am trying to get the 3rd file in below format. So, whenever difference is 0 it shouldnt appear but if the diffence is not 0 then it should appear like Value , File1 Value , File2 Value , Difference ---------------------------------------------- ABC:84, 53 ,1553 , -1500 ABC:14, 1222 , 0 , 1222 ABC:524, 0 ,2626 ,-2626 I tried doing it using awk to

how to transpose values two by two using shell?

て烟熏妆下的殇ゞ 提交于 2021-02-10 18:22:57
问题 I have my data in a file store by lines like this : 3.172704445659,50.011996744997,3.1821975358417,50.012335988197,3.2174797791605,50.023182479597 And I would like 2 columns : 3.172704445659 50.011996744997 3.1821975358417 50.012335988197 3.2174797791605 50.023182479597 I know sed command for delete ','(sed "s/,/ /") but I don't know how to "back to line" every two digits ? Do you have any ideas ? 回答1: One in awk: $ awk -F, '{for(i=1;i<=NF;i++)printf "%s%s",$i,(i%2&&i!=NF?OFS:ORS)}' file

How to loop over jq unique array in bash?

混江龙づ霸主 提交于 2021-02-10 17:52:37
问题 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" },