如何在printf字符串中使用破折号?
x=xxx
printf -v args "-x=%s" "$x"
printf "$var"
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:
./tmp.sh: line 2: printf: -x: invalid option
printf: usage: printf [-v var] format [arguments]
Run Code Online (Sandbox Code Playgroud)
我知道这是因为printf解释-x为一种选择,但如何克服它?
我printf用来创建一个字符串,该字符串将对应于命令行参数,如-x=xxx -y=yyy -z=zzz. 然后我想调用一个工具
eval $tool args
该命令sed $'s/[^[:print:]\t]//g'按原样打印我的 .txt 的每一行。
它是干什么用的?我在谷歌上找不到它。
例如:
sed $'s/[^[:print:]\t]//g' *.txt | wc -l
15909
cat *.txt | wc -l
15909
Run Code Online (Sandbox Code Playgroud)
没有对文件进行任何编辑。这个命令有什么作用
如何计算文件中以“.wsp”结尾的所有单词
more file
/application_1532998892988_0207/driver/BlockManager/memory/remainingOffHeapMem_MB.wsp
/spark/application_1532998892988_0207/driver/BlockManager/memory/memUsed_MB.wsp
Run Code Online (Sandbox Code Playgroud)
同时,我创建了这个语法
sed s'/\// / g' file | awk '{print $NF}' | grep -o '.wsp' | wc -l
Run Code Online (Sandbox Code Playgroud)
但这种语法不是那么优雅
几周前我编辑了 /etc/resolvconf.conf 添加了这一行:
name_servers="1.0.0.1 2606:4700:4700::1111,2606:4700:4700::1001"
Run Code Online (Sandbox Code Playgroud)
今天,我再次回去编辑它,并sudo vim /etc/resolvconf.conf以只读方式打开文件并覆盖w!失败。我尝试过su,并且sudo sh -c "vim /etc/resolvconf.conf"没有任何效果。
ls -l /etc/resolvconf.conf
-rw-r--r-- 1 root root 320 Jan 4 00:05 /etc/resolvconf.conf
Run Code Online (Sandbox Code Playgroud)
这里发生了什么事?这怎么可能?
我有一个包含来自数据记录系统的 1000 个文件的目录,每个文件可以有多达 40,000 行或更多行。挑战在于,有时数据并未从一个或多个传感器记录下来,因此会丢失,例如
文件1:
A,B,C,D,F
10,20,10,20,5
Run Code Online (Sandbox Code Playgroud)
文件2:
B,C,D,E,F
20,10,20,5,10
Run Code Online (Sandbox Code Playgroud)
文件3:
D,E,F
10,30,20
Run Code Online (Sandbox Code Playgroud)
所需的结果将所有文件合并/加入单个标题。如果输入文件缺少一列(因为传感器损坏),该部分将替换为空值
A,B,C,D,E,F
10,20,10,20,,5
,20,10,20,5,10
,,,10,30,20
Run Code Online (Sandbox Code Playgroud)
最后一列 F 始终存在,因为那是日期/时间戳。
我找到了这个答案,但是它假设所有文件的所有标题/列都相同
我还发现了这个问题Merging multiple CSV files for matching and non matching columns但答案不够完整,我无法使用它。
谢谢
BEGIN{FS=","; t1 = 0; n = 0; avg = 0; sum=0; printf("%-10s %9s\n%-10s %9s","Name", "Average", "----", "-------") }
{
if ($3 > 0){
t1 += $3;
n++;
}
sum = 0;
if($3 > 0 && $4 > 0 && $5 >0){
sum = $3 + $4 + $5;
avg = sum / 3;
}
else if($3 < 0 && $4 > 0 && $5 >0){
sum = $4 + $5;
avg = sum / 2;
}
else if($3 > 0 …Run Code Online (Sandbox Code Playgroud) #### #!/usr/bin/sh
FILE="/home/steven/.bash_profile"
STRING="export PATH="$PATH:/opt/mssql-tools/bin""
if [ -z $(grep "$STRING" "$FILE") ]; then
echo 'the string is exist' >&2
else
echo 'the string doesnt exist' >&2
fi
Run Code Online (Sandbox Code Playgroud)
#### # .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
#### # User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
Run Code Online (Sandbox Code Playgroud)
为什么它总是返回 is 存在?
bash ×3
awk ×2
grep ×2
linux ×2
sed ×2
shell-script ×2
centos ×1
command ×1
csv ×1
executable ×1
filesystems ×1
perl ×1
permissions ×1
printf ×1
shell ×1