bash

How can I grep for a regex containing multiple ranges with at least one occurence

巧了我就是萌 提交于 2021-02-16 21:42:31
问题 Given the following input I'm trying to grep for lines that begin with at least thee digits: 7.3M ./user1 7.3M ./user2 770M ./user3 78M ./user4 737M ./user5 7.6M ./user6 My grep command is not working: grep ^[0-9]+[0-9]+[0-9]+M I don't understand why unfortunately. 回答1: Your regex, ^[0-9]+[0-9]+[0-9]+M , would match the start of string ( ^ ), then 1+ diigts (but it does not because + is not compatible with POSIX BRE that you are using since there is no -E nor -P options), then again 1+ digits

cd to a folder name starting with tilde (~) in bash script

此生再无相见时 提交于 2021-02-16 21:15:29
问题 I'm trying to create a very simple bash script that does the following: Inputs the user to enter a project folder Sets the value entered in a variable cd to the folder entered remove the readme.md file From what I've read around I've come up with this: #!/bin/bash echo "Enter the project folder path:" read -e DESTINATION_FOLDER cd "$DESTINATION_FOLDER" rm -rf "$DESTINATION_FOLDER/readme.md" The folder's path I entered was ~/Dropbox/myproject And the error I get is the one below. However that

Bash script with multiple papermill commands does not fail on notebook errors

无人久伴 提交于 2021-02-16 20:55:25
问题 I have a refresh_data.sh file which contains multiple papermill commands, for example: papermill notebook_1.ipynb output_1.ipynb -p start "2017-12-01" -p date "2017-12-31" papermill notebook_2.ipynb output_2.ipynb -p start "2018-01-01" -p date "2018-01-31" If I get an error while it is running the first notebook, the process continues executing the second one. In other words, an error in one of the notebooks doesn't "break" the overall script. As far as I remember with normal python scripts

Bash script with multiple papermill commands does not fail on notebook errors

断了今生、忘了曾经 提交于 2021-02-16 20:55:12
问题 I have a refresh_data.sh file which contains multiple papermill commands, for example: papermill notebook_1.ipynb output_1.ipynb -p start "2017-12-01" -p date "2017-12-31" papermill notebook_2.ipynb output_2.ipynb -p start "2018-01-01" -p date "2018-01-31" If I get an error while it is running the first notebook, the process continues executing the second one. In other words, an error in one of the notebooks doesn't "break" the overall script. As far as I remember with normal python scripts

Linux编程_Shell脚本练习题

为君一笑 提交于 2021-02-16 20:49:05
1,编写shell脚本,计算1~100的和。 #! /bin/ bash sum = 0 for i in ` seq 1 100 `; do sum =$[$i+$ sum ] done echo $ sum 2,编写shell脚本,输入一个数字n并计算1~n的和。 要求:如果输入的数字小于1,则重新输入,直到输入正确的数字为止。 #! /bin/ bash read -p " input number: " n sum = 0 ; for ((i= 0 ;i<=$n;i++ )) do sum =` expr $ sum + $i` done echo $ sum 3,编写shell脚本,批量建立用户user_00、user_01...user_99。 要求:所有用户同属于users组。 #! /bin/ bash groupadd users for i in ` seq - w 0 9 uesradd - g users user_0$i4 done 4,编写shell脚本,批量添加用户 jsj01-jsj09、jsj10-jsj99。 #! /bin/ bash for ((i= 1 ;i< 20 ;i++ )); do if (i< 10 ); then jsj = " jsj0$i " ; else jsj = " jsj$i " ; fi useradd $jsj

10月12日任务

落爺英雄遲暮 提交于 2021-02-16 20:45:20
10月12日任务 8.6 管道符和作业控制 管道符| 将前一个指令的输出作为后一个指令的输入。 #cat 1.txt |wc -l [root @centos7 ~]# cat 1.txt |wc -l 统计行数 2 [root @centos7 ~]# ls 1.txt 1.xtx 2.txt 3.txt 4.txt a_(2).txt AA.txt anaconda-ks.cfg anaconda-ks.cfg.1 a.txt A.txt bb.txt err temp.1 [root @centos7 ~]# ls |wc -l 统计文件数量 14 #cat 1.txt |grep 'aaa'在1.txt中过滤'aaa',并显示出相关'aaa'的信息。 ctrl z暂停一个任务 假如,在使用#vim 1.txt写入信息时,想退出当前vim窗口去做其他操作又不想影响数据录入,又不想wq退出。这时候可以使用ctrl z去把任务暂停。 [root @centos7 ~]# vim 1.txt [1]+ 已停止 vim 1.txt [root @centos7 ~]# cat 1.txt 1.txt 2.txt jobs查看后台的任务 # jobs [1]- 已停止 vim 1.txt [2]+ 已停止 vim a.txt fg[id]把任务调到前台 #fg 可以把被暂停的任务调出来

Split string into array using multi-character delimiter

自作多情 提交于 2021-02-16 20:26:11
问题 I need to split a string into an array. My problem is that the delimiter is a 3 character one: _-_ For example: db2-111_-_oracle12cR1RAC_-_mariadb101 I'd need to create the following array: db2-111 oracle12cR1RAC mariadb101 Similar questions followed this approach: str="db2-111_-_oracle12cR1RAC_-_mariadb101" arr=(${str//_-_/ }) echo ${arr[@]} Even if the array is created, it has been split uncorrectly: db2 111 oracle12cR1RAC mariadb101 It seems that the "-" character in the first item causes

Awk asking combine two files

纵饮孤独 提交于 2021-02-16 20:17:37
问题 I have combined two different files with Same Key by AWK command. And In case there is no key match compare to File1 and File2 then just put "\t\t\t" instead. I have below AWK command. awk -F"\t" ' {key = $1} NR == 1 {header = key} !(key in result) {result[key] = $0 ; next} { for (i=2; i <= NF; i++) result[key] = result[key] FS $i } END { print result[header],"\tValue2","\tValue3","\tValue4" delete result[header] PROCINFO["sorted_in"] = "@ind_str_asc" # if using GNU awk for (key in result)

How to show read prompt with a new line

白昼怎懂夜的黑 提交于 2021-02-16 20:17:22
问题 I'm using read builtin to read a variable, but I'd like to let the input appears on the next line, that is, the prompt output a new line, but neither of the two works: $ read -p "Please input:\n" name Please input:\n $ read -p 'Please input:\n" name Please input:\n As you see new line escape sequence is not interpreted even in the double quote case. So is there anyway to do that? 回答1: You can separate the prompt from the actual read : echo "Please input:" read name You can put both on a

“Command not found” piping a variable to cut when output stored in a variable [duplicate]

谁说我不能喝 提交于 2021-02-16 20:17:16
问题 This question already has answers here : How to pass the value of a variable to the stdin of a command? (9 answers) Closed 3 years ago . In a bash script I am using a variable to hold a path like this: MY_DIR=/just/a/string/to/my/path And I want to remove the last two parts of it so it looks like this: /just/a/string I am using 'cut' to do it, like this: echo $MY_DIR | cut -d'/' -f-4 The output is what I expect. Fine. But I want to store in an other variable, like this: MY_DIR2=$($MY_DIR |