grep当一行包含与表达式匹配的字符串时,Command将打印一行,这对于搜索指定的内容并不方便。
例如,我有带格式的词汇文件
**word**
1. Definition:
2. Usage
3. Others
Run Code Online (Sandbox Code Playgroud)
我想检索所有单词以在文件中制作单词表
grep '\*\*[^*]*\*\*'
Run Code Online (Sandbox Code Playgroud)
返回大部分内容。
如何使用grep仅捕获word?
在尝试启动 dropbox 时,它提示
$ dropbox start
Starting Dropbox...
The Dropbox daemon is not installed!
Run "dropbox start -i" to install the daemon
Run Code Online (Sandbox Code Playgroud)
按照指示,
$ dropbox start -i
Starting Dropbox...Traceback (most recent call last):
File "/usr/bin/dropbox", line 1443, in start
download()
File "/usr/bin/dropbox", line 294, in download
import gi
ModuleNotFoundError: No module named 'gi'
Run Code Online (Sandbox Code Playgroud)
然后尝试安装gi
$ pip install gi
Collecting gi
Could not find a version that satisfies the requirement gi (from versions: )
No matching distribution found for gi
Run Code Online (Sandbox Code Playgroud)
版本: …
我想找到所有后缀为.md或的文件.org
find ~ -iregex ".*\.md$"
find ~ -iregex ".*\.org$"
Run Code Online (Sandbox Code Playgroud)
怎么可能把它们结合起来?
我有一个包含 64895 个字符的文件
In [95]: !wc -c 07.org
64895 07.org
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到位置 60000 的字符?
我在sed中测试了单引号和双引号
me@host:~:
$ echo "front" | sed "s/front/back/"
back
me@host:~:
$ echo "front" | sed 's/front/back/'
back
Run Code Online (Sandbox Code Playgroud)
它们的表现相同,但我记得几个月前读到它们之间存在差异。
Google 搜索对关键字“sed 中的单引号和双引号”没有帮助。
它们不完全相同,对吧?
我打算计算一个圆的面积。
#! /usr/local/bin/bash
read -p "Enter a radius: "
area () {
a=$(( 3 * $REPLY * 2 ))
return $a
}
echo $(area)
Run Code Online (Sandbox Code Playgroud)
运行但不返回
$ bash area.sh
Enter a radius: 9
Run Code Online (Sandbox Code Playgroud)
然后通过引用重构它
#! /usr/local/bin/bash
read -p "Enter a radius: " radius
area (radius) {
a=$(( 3 * $radius * 2 ))
return "$a"
}
echo "$(area)"
Run Code Online (Sandbox Code Playgroud)
它仍然无法正常工作。
bash area.sh
Enter a radius: 9
area.sh: line 3: syntax error near unexpected token `radius'
area.sh: line 3: `area (radius) {'
Run Code Online (Sandbox Code Playgroud)
如何进行这样的计算?