我有 2 个命令需要每小时运行一次,所以我将它们放在 /etc/cron.hourly/hrcron 文件中,格式如下
command1; command2
Run Code Online (Sandbox Code Playgroud)
在我看来它应该有效,但是有没有人知道阻止它运行的原因是什么?
我正在运行 CentOS 6.8。
有没有办法知道哪些文件受到终端中输入的任何命令的影响?例如,我们都知道passwd命令的作用,以及它影响的文件。但是有没有明确的方法可以知道任何命令影响的确切文件名?
我有一个将用户添加到文件的命令,该命令对这些用户实施了一些策略。但我不确定它添加到哪个文件。
I have non-standard data, which I'd like to standardise
file:
d101 11001
e101 9665
f101 9663
d102 11002
e102 11003
f102 11004
g102 11005
Run Code Online (Sandbox Code Playgroud)
desired output:
d101 11001
e101 12001
f101 12002
d102 11002
e102 11003
f102 11004
g102 11005
Run Code Online (Sandbox Code Playgroud)
so the logic should be, if length of column2 = 4 it should replace it with incremental numbering of a provided series: in this case 1200 is series, & 1, 2, 3 .. are increments.
我想构造一个函数,该函数将根据其参数更改其用户输入提示。
my_fucntiondb_host提示用户输入后采用 1 个参数:
function provide_host () {
echo "Enter NAME OR IP OF ${function_param1} DATBASE HOST: "
read global function_param1_db_host
}
Run Code Online (Sandbox Code Playgroud)
所以如果我将该函数称为
function provide_host (primary)
Run Code Online (Sandbox Code Playgroud)
它应该提示为
echo "Enter NAME OR IP OF PRIMARY DATBASE HOST: "
Run Code Online (Sandbox Code Playgroud)
但如果我用
function provide_host (secondary)
Run Code Online (Sandbox Code Playgroud)
它提示
"Enter NAME OR IP OF SECONDARY DATBASE HOST: "
Run Code Online (Sandbox Code Playgroud)
我的想法是我必须if为此使用一个语句,但我不确定是否可以使用函数的参数作为变量来提示用户在函数内。
我有"|"分隔的文本数据,并且想要转换列值
$ cat infile
Mark|father
Jason|SOn
Jose|son
Steffy|daugHter
Run Code Online (Sandbox Code Playgroud)
我想不敏感地搜索 (father|son|daughter) 大小写并将任何情况下的父亲替换为父亲,将任何情况下的儿子替换为儿子,将任何情况下的女儿替换为女儿
所以输出文件应该是这样的
$ cat outfile
Mark Father
Jason Son
Jose Son
Steffy Daughter
Run Code Online (Sandbox Code Playgroud)
我正在尝试 IGNORECASE 与 sub 或 gsub 的不同组合,但它会按 infile 中的原样打印所有条目
我有一个数据文件,日期在第二列
# cat datafile
-;20210106;-;-;-;
-;20210112;-;-;-;
-;20210112;-;-;-;
-;20210112;-;-;-;
...
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210219;-;-;-;
-;20210219;-;-;-;
-;20210221;-;-;*20210219*;
Run Code Online (Sandbox Code Playgroud)
连字符“ -”代表随机文本数据,点“ ”...代表更多行数据,“*”代表同一列中的随机文本。我想要的只是基于第二列之间的20210112数据20210219。
我想避免,sed/grep因为两者也会在其他列中 grep 类似的模式。
# sed -n '/20210112/,/20210219/p' datafile
-;20210112;-;-;-;
-;20210112;-;-;-;
-;20210112;-;-;-;
...
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210219;-;-;-;
-;20210219;-;-;-;
-;20210221;-;-;*20210219*;
Run Code Online (Sandbox Code Playgroud)
它也会匹配其他不相关行中的一些其他文本。所以,我猜 AWK 是一个更好的候选者,但我注意到 awk 仅在第一个模式的第一个匹配到第二个模式的第一个匹配之间打印
# awk -F';' '$2 ~ /20210112/,$2 ~ /20210219/' datafile
-;20210112;-;-;-;
-;20210112;-;-;-;
-;20210112;-;-;-;
...
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210219;-;-;-;
Run Code Online (Sandbox Code Playgroud)
然而,我想将所有行带到第二个模式的最后一场比赛。
-;20210112;-;-;-;
-;20210112;-;-;-;
-;20210112;-;-;-;
...
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-;
-;20210217;-;-;-; …Run Code Online (Sandbox Code Playgroud) 我有一个包含值的文件,有些是整数,有些是小数
# cat file
value1 100
value2 500.10
value3 2505
value4 35.4
Run Code Online (Sandbox Code Playgroud)
我想将 field2 中的每个值除以固定数字 = 1000,并在除法后将所有值相加。结果值必须保留小数点后 5 位
# cat output.txt
value1 100 0.10000
value2 500.10 0.50010
value3 2505 2.50500
value4 35.4 0.03450
sum 3140.50000 3.14050
Run Code Online (Sandbox Code Playgroud) 我有这样的文件
d1000 1000
d1001 100
d1002 10
d1003 1
Run Code Online (Sandbox Code Playgroud)
我想修改长度不等于 4 的第二列。但我只想打印修改的行,因此第 2 列中的原始文本保留在 coulmn 2 中,更改打印在第三列中,并递增到一个数字。
期望的输出:
d1001 100 1101
d1002 10 1102
d1003 1 1103
Run Code Online (Sandbox Code Playgroud)
我正在尝试按照这些思路,但无法获得语法或结果
awk -v n=1100 '((length($2)!=4 && length($2)>0) {new=($2=++n)}; {print $1, $2, new}' file
Run Code Online (Sandbox Code Playgroud) 我有 2 个文件,第一行是标题行供参考
file1
userId userContact parentId parentContact
200 0900200 100 -
201 0900201 100 -
300 0900300 101 -
Run Code Online (Sandbox Code Playgroud)
file2
userId userContact parentId parentContact
100 0900100 100 -
101 0900101 100 -
Run Code Online (Sandbox Code Playgroud)
我想填充 的第四列file1,以便它必须搜索$3in ,然后用from代替 of ,file1因此$1输出
应如下所示:file2$2file2$4file1
output
userId userContact parentId parentContact
200 0900200 100 0900100
201 0900201 100 0900100
300 0900300 101 0900101
Run Code Online (Sandbox Code Playgroud)
我更喜欢awk,因为它会更快。
awk ×6
bash ×1
command-line ×1
cron ×1
function ×1
grep ×1
parameter ×1
replace ×1
scheduling ×1
search ×1