小编pan*_*ear的帖子

在管道之后,该命令被视为以空格为前缀

当我键入时,有时在我的终端(Ubuntu)上:

ls | grep toto
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

 grep: command not found*
Run Code Online (Sandbox Code Playgroud)

请注意,shell正在编写以空格为前缀的grep.这怎么可能?

bash ubuntu grep pipe

11
推荐指数
2
解决办法
2261
查看次数

如何在Vim脚本中执行"for char in string"之类的操作?

我想出了这个,但是我错过了简单的方法吗?

for s:char in split(s:string, '.\zs\ze.')
Run Code Online (Sandbox Code Playgroud)

vim

7
推荐指数
1
解决办法
1103
查看次数

如何更改grep查看文件/打印结果的顺序?

我有一个目录,其中包含一堆带有数字文件名的文件.它们没有前导零,所以如果我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的颜色,我想保留它.最好的方法是什么?

linux bash grep gnu

4
推荐指数
1
解决办法
6351
查看次数

使用shell命令按字符串对齐文本

说我在这样的文件中有一些文字:

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可以列出内容,但它只能使用空格或字符(不是字符串或模式)作为分隔符.

shell awk printf sed

1
推荐指数
1
解决办法
814
查看次数

将嵌套的"where"应用于另外两个绑定的地方

我想做这样的事情:

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.

我该怎么做?

haskell

1
推荐指数
1
解决办法
263
查看次数

pyteaser中以下编码的含义是什么?

我目前正在使用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)

python

-1
推荐指数
1
解决办法
374
查看次数

标签 统计

bash ×2

grep ×2

awk ×1

gnu ×1

haskell ×1

linux ×1

pipe ×1

printf ×1

python ×1

sed ×1

shell ×1

ubuntu ×1

vim ×1