bash

bash script to run jupyter notebook in virtualenv

一世执手 提交于 2021-02-19 04:18:25
问题 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

Nested while read loops with fd

混江龙づ霸主 提交于 2021-02-19 04:04:13
问题 I'm trying to read from two different inputs in nested loops without success. I've followed the best answer on this question and also took a look at the file descriptors page of the Advanced Bash-Scripting Guide . Sample script I made to test my problem. #!/bin/bash while read line <&3 ; do echo $line while read _line <&4 ; do echo $_line done 4< "sample-2.txt" done 3< "sample-1.txt" Content of sample-1.txt Foo Foo Content of sample-2.txt Bar Bar Expected output Foo Bar Bar Foo Bar Bar The

Change grid size of a netCDF file

折月煮酒 提交于 2021-02-19 03:19:19
问题 Let's assume I have 2 netCDF data files with data for the same region (like South America, Africa, etc) but the different grid sizes as 0.5 degrees x 0.5 degrees and 1.0 degrees x 1.0 degrees in another. I want to increase or decrease its grid size to a different value such as 0.25 x 0.25 or 1.0 x 1.0 so that I can use this easily for raster calculations and comparison, etc. Is there a method to do this using any bash script, CDO, etc. A sample data can be downloaded from here. https://www

Change grid size of a netCDF file

谁说我不能喝 提交于 2021-02-19 03:18:57
问题 Let's assume I have 2 netCDF data files with data for the same region (like South America, Africa, etc) but the different grid sizes as 0.5 degrees x 0.5 degrees and 1.0 degrees x 1.0 degrees in another. I want to increase or decrease its grid size to a different value such as 0.25 x 0.25 or 1.0 x 1.0 so that I can use this easily for raster calculations and comparison, etc. Is there a method to do this using any bash script, CDO, etc. A sample data can be downloaded from here. https://www

Change grid size of a netCDF file

。_饼干妹妹 提交于 2021-02-19 03:18:37
问题 Let's assume I have 2 netCDF data files with data for the same region (like South America, Africa, etc) but the different grid sizes as 0.5 degrees x 0.5 degrees and 1.0 degrees x 1.0 degrees in another. I want to increase or decrease its grid size to a different value such as 0.25 x 0.25 or 1.0 x 1.0 so that I can use this easily for raster calculations and comparison, etc. Is there a method to do this using any bash script, CDO, etc. A sample data can be downloaded from here. https://www

3.Shell 接收用户的参数

左心房为你撑大大i 提交于 2021-02-19 02:41:15
1.Shell 传递参数   我们可以在执行 Shell 脚本时,向脚本传递参数,Linux系统中的Shell脚本语言已经内设了用于接收参数的变量,变量之间可以使用空格间隔。   例如$0对应的是当前Shell脚本程序的名称,$#对应的是总共有几个参数,$*对应的是所有位置的参数值,$?对应的是显示上一次命令的执行返回值, 而$1、$2、$3……则分别对应着第N个位置的参数值,如图4-15所示 尝试编写一个脚本程序示例: [root@linuxprobe ~]# vim example. sh # !/bin/ bash echo " 当前脚本名称为$0 " echo " 总共有$#个参数,分别是$*。 " echo " 第1个参数为$1,第5个为$5。 " [root@linuxprobe ~]# sh example. sh one two three four five six 当前脚本名称为example. sh 总共有6个参数,分别是one two three four five six。 第1个参数为one,第5个为five。 $* 与 $@ 区别: 相同点:都是引用所有参数。 不同点:只有在双引号中体现出来。假设在脚本运行时写了三个参数 1、2、3,,则 " * " 等价于 "1 2 3"(传递了一个参数),而 "@" 等价于 "1" "2" "3"(传递了三个参数)

Shell 基本运算符

纵饮孤独 提交于 2021-02-19 01:40:30
Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用。 expr 是一款表达式计算工具,使用它能完成表达式的求值操作。 例如,两个数相加(注意使用的是反引号 ` 而不是单引号 '): #!/bin/bash val=`expr 2 + 2` echo "两数之和为 : $val" 两点注意: 表达式和运算符之间要有空格,例如 2+2 是不对的,必须写成 2 + 2,这与我们熟悉的大多数编程语言不一样。 完整的表达式要被 ` ` 包含,注意这个字符不是常用的单引号,在 Esc 键下边。 算术运算符 下表列出了常用的算术运算符,假定变量 a 为 10,变量 b 为 20: 运算符 说明 举例 + 加法 `expr $a + $b` 结果为 30。 - 减法 `expr $a - $b` 结果为 -10。 * 乘法 `expr $a \* $b` 结果为 200。 / 除法 `expr $b / $a` 结果为 2。 % 取余 `expr $b % $a` 结果为 0。 = 赋值 a=$b 将把变量 b 的值赋给 a。 == 相等。用于比较两个数字,相同则返回 true。 [ $a == $b ] 返回 false

Shell编程(三) : shell基本运算符

戏子无情 提交于 2021-02-18 23:22:42
shell 基本运算符 shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用。 expr 是一款表达式计算工具,使用它能完成表达式的求值操作。 实例 例如,两个数组相加(注意使用的是反引号 而不是单引号 ) #!/bin/bash val=`expr 2 + 2` echo "两数之和为 : $val" 两点注意: 表达式和运算符之间要有空格,例如 2+2 是不对的,必须写成 2 + 2,这与我们熟悉的大多数编程语言不一样。 完整的表达式要被 包含,注意这个字符不是常用的单引号,在 Esc 键下边。 算数运算符 运算符 说明 举例 + 加法 expr $a + $b 结果为 30。 - 减法 expr $a - $b 结果为 -10。 * 乘法 expr $a \* $b 结果为 200。 / 除法 expr $b / $a 结果为 2。 % 取余 expr $b % $a 结果为 0。 = 赋值 a=$b 将把变量 b 的值赋给 a。 == 相等 [ $a == $b ] 返回 false。 = 不相等 [ $a != $b ] 返回 true。 注意:条件表达式要放在方括号之间,并且要有空格,例如: [

How to print the next word after a found pattern with grep,sed and awk?

北城余情 提交于 2021-02-18 22:26:28
问题 for example, suppose I have logfile.txt which contains "Here is a sample text file" My pattern is "sample" How can I get the word next to sample in my logfile.txt. 回答1: Here is one way to do it with awk: $ awk '{for(i=1;i<=NF;i++)if($i=="sample")print $(i+1)}' file text Explained: $ awk '{ for(i=1;i<=NF;i++) # process every word if($i=="sample") # if word is sample print $(i+1) # print the next }' file and sed: $ sed -n 's/.* sample \([^ ]*\).*/\1/p' file text ie. after sample next space

AWS SQS not receiving SNS messages

旧巷老猫 提交于 2021-02-18 20:48:05
问题 I created a SNS topic that publishes all the information coming out of Cloudformation via the cli. However, when I check the queue, it is not receiving any of the SNS messages. I verified the SNS is working by subscribing my email to it, so the issue seems to be in the connection between the queue and the SNS. However, I cannot find any problems with my syntax. I, as far as I know, have followed amazon's documentation precisely. Bash: #SNS parameters SNS_NAME="${NAME}_SNS" SQS_NAME="${NAME}