当我键入时,有时在我的终端(Ubuntu)上:
ls | grep toto
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
grep: command not found*
Run Code Online (Sandbox Code Playgroud)
请注意,shell正在编写以空格为前缀的grep.这怎么可能?
我想出了这个,但是我错过了简单的方法吗?
for s:char in split(s:string, '.\zs\ze.')
Run Code Online (Sandbox Code Playgroud) 我有一个目录,其中包含一堆带有数字文件名的文件.它们没有前导零,所以如果我grep hello *
在该目录中执行类似的操作,我可能会得到类似这样的内容:
22:hello, world!
6:hello
62:"Say hello to them for me."
Run Code Online (Sandbox Code Playgroud)
我宁愿让结果像这样:
6:hello
22:hello, world!
62:"Say hello to them for me."
Run Code Online (Sandbox Code Playgroud)
发生在我身上的第一个想法是用数字方式对结果进行排序,grep hello * | sort -n
但后来我失去了grep的颜色,我想保留它.最好的方法是什么?
说我在这样的文件中有一些文字:
lorem ipsum asdf gh 12345
hello, world! asdf gh this is a test
ee asdf gh ii
Run Code Online (Sandbox Code Playgroud)
请注意,每行包含"asdf gh".我希望能够使用一些shell命令来基于该分隔符字符串对齐该文本,所以我可以这样做:
$ cat my-file | some-command
lorem ipsum asdf gh 12345
hello, world! asdf gh this is a test
ee asdf gh ii
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我在分隔符周围添加了额外的空格,但这两种方式都没有关系.也就是说,输出也可以是:
$ cat my-file | some-command
lorem ipsum asdf gh 12345
hello, world! asdf gh this is a test
ee asdf gh ii
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法吗?我知道column
可以列出内容,但它只能使用空格或字符(不是字符串或模式)作为分隔符.
我想做这样的事情:
foo x = a + b
where
a = bar z
b = baz z
where
z = qux x
Run Code Online (Sandbox Code Playgroud)
但那不是有效的Haskell; z = qux x
适用于b = baz z
,但不适用于a = bar z
.
我该怎么做?
我目前正在使用pyteaser进行汇总,效果很好.我正在查看源代码,但即使借助下面的评论,我也不理解以下编码.任何人都可以解释一下吗?
def split_sentences(text):
'''
The regular expression matches all sentence ending punctuation and splits the string at those points.
At this point in the code, the list looks like this ["Hello, world", "!" ... ]. The punctuation and all quotation marks
are separated from the actual text. The first s_iter line turns each group of two items in the list into a tuple,
excluding the last item in the list (the last item in the list does not need to …
Run Code Online (Sandbox Code Playgroud)