bash

GREP by result of awk

China☆狼群 提交于 2021-02-19 06:22:42
问题 Output of awk '{print $4}' is b05808aa-c6ad-4d30-a334-198ff5726f7c 59996d37-9008-4b3b-ab22-340955cb6019 2b41f358-ff6d-418c-a0d3-ac7151c03b78 7ac4995c-ff2c-4717-a2ac-e6870a5670f0 I need to grep file st.log by these records. Something like awk '{print $4}' |xargs -i grep -w "pattern from awk" st.log I dont know how to pass pattern correctly? 回答1: What about awk '{print $4}' | grep -F -f - st.log Credits to Eric Renouf, who noticed that -f - can be used for standard input instead -f <(cat) ,

Silence /dev/tcp/host/port redirection errors

跟風遠走 提交于 2021-02-19 06:01:38
问题 The following script will test if tcp port from 8079 to 8081 is open or closed. for port in {8079..8081}; do echo >/dev/tcp/127.0.0.1/$port && echo "port $port is open" || echo "port $port is closed" done Output user@linux:~$ ./script.sh ./script.sh: connect: Connection refused ./script.sh: line 2: /dev/tcp/127.0.0.1/8079: Connection refused port 8079 is closed port 8080 is open ./script.sh: connect: Connection refused ./script.sh: line 2: /dev/tcp/127.0.0.1/8081: Connection refused port 8081

VSCode: Code Runner extension is unable to execute the code on git bash terminal?

天涯浪子 提交于 2021-02-19 05:55:11
问题 I am trying to run a simple program "primeRange.cpp" using Code Runner extension available for VSCode. I have selected my default terminal as git bash in VSCode , but when I hit Run on top right corner, it sends the command to bash to run the program using g++ compiler, but I am getting error as no such file or directory , when there exists a directory with the given name. How can I fix this? How can I customize which command to hit on bash when I press run on code runner? I want to set the

Convert JSON to CSV with jq

懵懂的女人 提交于 2021-02-19 05:50:08
问题 I'm trying to extract the sids, ll, state, name, smry values in my JSON file using jq and export to a csv. JSON File (out.json): { "data": [ { "meta": { "uid": 74529, "ll": [ -66.9333, 47.0667 ], "sids": [ "CA008102500 6" ], "state": "NB", "elev": 1250, "name": "LONG LAKE" }, "smry": [ [ "42", "1955-02-23" ] ] }, { "meta": { "uid": 74534, "ll": [ -67.2333, 45.9667 ], "sids": [ "CA008103425 6" ], "state": "NB", "elev": 150.9, "name": "NACKAWIC" }, "smry": [ [ "40", "1969-02-23" ] ] }, { "meta"

Can't find process listed by `jobs` command

不羁岁月 提交于 2021-02-19 05:34:33
问题 I am using jobs command to control the number of compute-intensive processes. I want to not run more than max_cnt processes at a time, and stop only when all the processes have stopped. I use below bash script to accomplish this. However, this code always lists one process as running even after everything has executed and stopped. Moreover, I can't find that process listed in htop 's list of processes. What should I do or where should I look for that process that is listed by the result of

Bash processing of csv file with unknown number of columns

只愿长相守 提交于 2021-02-19 05:22:04
问题 I am trying to learn some text processing using bash. How to make a bash script to read and process CSV file with unknown number of columns with first row as column headers? Example input: column1,column2,...,columnn value11,value12,...,value1n value21,value22,...,value2n ... valuem1,valuem2,...,valuemn output: column1: value11 column2: value12 ... columnn: value1n column1: value21 column2: value22 ... columnn: value2n ... column1: valuem1 column2: valuem2 ... columnn: valuemn 回答1: One simple

Call php function from bash - with arguments

余生颓废 提交于 2021-02-19 05:20:25
问题 I have a simple func.php file with concat function: <?php function concat($arg1, $arg2) { return $arg1.$arg2; } ?> I would like to call this function from linux bash shell with two arguments : 1st: "Hello, " 2nd: "World!" and print the output ("Hello, World!") to linux bash shell. Please tell me, how to do it? 回答1: What you want is $argv So for example, your script would be called like this: php /path/to/script.php 'Hello, ' 'World!' Then in your PHP file: <?php $arg1 = $argv[1]; $arg2 =

Create directory for log file before calling slurm sbatch

跟風遠走 提交于 2021-02-19 05:16:21
问题 Slurm sbatch directs stdout and stderr to the files specified by the -o and -e flags, but fails to do so if the filepath contains directories that don't exist. Is there some way to automatically make the directories for my log files? Manually creating these directories each time is inefficient because I'm running each sbatch submission dozens of times. Letting the variation over job names exist in filenames rather than directories makes for a huge, poorly organized mess of logs I have to sort

VSCode terminal not showing current folder

痞子三分冷 提交于 2021-02-19 05:10:34
问题 When I open integrated terminal in VS Code, the initial screen showing "bash-3.2", see my screen shot When I looked any online examples, it always showing current path or folder, such as the image in official page. I was wondering how could I change the setting so that integrated terminal can show at least current folder that I am running the command. Please advise. ===updated==== I am sorry that I forgot to mention my OS is macOS sierra 回答1: Found the answer. You should add the following to

bash script to run jupyter notebook in virtualenv

人走茶凉 提交于 2021-02-19 04:19:20
问题 To speed up launching projects I created a small bash script which does the following: takes an argument (project name) moves to the directory of that project starts a virtual environment starts a jupyter notebook #!/bin/bash if [ "$1" == "k3" ]; then project_path="tau-code/k3-analysis/" fi codepath="/media/peter/somedrive/code" full_path="$codepath/$project_path" # Go to directory of project cd $full_path # Start environment & notebook if available pipenv shell jupyter notebook --ip=0.0.0.0