我试图为shell脚本经常使用的路径制作一个"别名".我试了一下,但失败了:
myFold="~/Files/Scripts/Main"
cd myFold
bash: cd: myFold: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我如何使其工作?
但是,cd ~/Files/Scripts/Main
工作.
我有一个文本文件:
1 Q0 1657 1 19.6117 Exp
1 Q0 1410 2 18.8302 Exp
2 Q0 3078 1 18.6695 Exp
2 Q0 2434 2 14.0508 Exp
2 Q0 3129 3 13.5495 Exp
Run Code Online (Sandbox Code Playgroud)
我想把每一行的第2和第4个单词都这样:
1657 19.6117
1410 18.8302
3078 18.6695
2434 14.0508
3129 13.5495
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码:
nol=$(cat "/path/of/my/text" | wc -l)
x=1
while [ $x -le "$nol" ]
do
line=($(sed -n "$x"p /path/of/my/text)
echo ""${line[1]}" "${line[3]}"" >> out.txt
x=$(( $x + 1 ))
done
Run Code Online (Sandbox Code Playgroud)
它有效,但它非常复杂,需要很长时间才能处理长文本文件.
有更简单的方法吗?
我编写了一个脚本来检索某些值file.json
.如果我向jq提供值,它可以工作select
,但变量似乎不起作用(或者我不知道如何使用它).
#!/bin/sh
#this works ***
projectID=$(cat file.json | jq -r '.resource[] | select(.username=="myemail@hotmail.com") | .id')
echo "$projectID"
EMAILID=myemail@hotmail.com
#this does not work *** no value is printed
projectID=$(cat file.json | jq -r '.resource[] | select(.username=="$EMAILID") | .id')
echo "$projectID"
Run Code Online (Sandbox Code Playgroud) 我想在通常有很长行的HTML文件上运行ack或grep.我不想看到很长的线条反复包裹.但我确实希望看到围绕与正则表达式匹配的字符串的长行的那一部分.如何使用任何Unix工具组合获得此功能?
我想将文件的第二行存储到变量中,所以我这样做:
sed -n '2p' myfile
Run Code Online (Sandbox Code Playgroud)
我希望将sed
命令的输出存储到名为的变量中line
.
这样做的正确语法是什么?
如何在已被引号包围的sed表达式中转义单引号?
例如:
sed 's/ones/one's/' <<< 'ones thing'
Run Code Online (Sandbox Code Playgroud) 有没有办法让编译的命令行程序告诉bash或csh它不希望扩展其参数中的任何通配符?
例如,可能需要一个shell命令,如:
foo *
Run Code Online (Sandbox Code Playgroud)
简单地返回该字符的数字ASCII值.
亲爱的开发者,
我有这个问题,这对我来说似乎有点奇怪.看一下这段代码:
package coreinterfaces
type FilterInterface interface {
Filter(s *string) bool
}
type FieldFilter struct {
Key string
Val string
}
func (ff *FieldFilter) Filter(s *string) bool {
// Some code
}
type FilterMapInterface interface {
AddFilter(f *FilterInterface) uuid.UUID
RemoveFilter(i uuid.UUID)
GetFilterByID(i uuid.UUID) *FilterInterface
}
type FilterMap struct {
mutex sync.Mutex
Filters map[uuid.UUID]FilterInterface
}
func (fp *FilterMap) AddFilter(f *FilterInterface) uuid.UUID {
// Some code
}
func (fp *FilterMap) RemoveFilter(i uuid.UUID) {
// Some code
}
func (fp *FilterMap) GetFilterByID(i uuid.UUID) …
Run Code Online (Sandbox Code Playgroud) 如何跳过循环使用pdb.set_trace()
?
例如,
pdb.set_trace()
for i in range(5):
print(i)
print('Done!')
Run Code Online (Sandbox Code Playgroud)
pdb
在循环之前提示.我输入一个命令.返回所有1-5个值,然后我希望pdb
在print('Done!')
执行之前再次提示.
我有一个看起来像这样的字符串:
GenFiltEff=7.092200e-01
Run Code Online (Sandbox Code Playgroud)
使用bash,我想在=
角色后面得到数字.有没有办法做到这一点?