小编use*_*191的帖子

unix中shell命令的"找不到事件"错误

当我试图删除连续的重复行

awk "!x[$0]++" file

它的报道 x[: Event not found.

甚至同样的情况

sed -i -e "$!N; /^\(.*\)\n\1$/!P;D" file 以及报告

N: Event not found. 我也试过单引号,但没有帮助

任何想法来解决这些问题

unix shell awk sed tcsh

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

使用Visual Block模式删除VIM/gvim中的特定列

示例输入文件

+--------------------+---------+---------
|           Name     |   S1    |    S2
+--------------------+---------+---------
|           A        | -4.703  | -2.378  
|           B        | -3283.2 | -3204.5 
|           C        |  8779   |  7302   
|           D        |  22078  |  18018  
+--------------------+---------+---------
Run Code Online (Sandbox Code Playgroud)

需要删除S1列,即

期望的输出

+--------------------+---------
|           Name     |   S2    
+--------------------+---------
|           A        | -2.378    
|           B        | -3205.5  
|           C        |  7302      
|           D        |  18018    
+--------------------+---------
Run Code Online (Sandbox Code Playgroud)

有人能帮忙吗

谢谢

vim

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

python中的文件路径层次排序

输入文件包含文件路径列表.建议算法做下面的层次排序输出

输入

A/file1
A/B/C/D/file3
A/B/file1
A/B/file2
A/B/C/D/file1
A/file2
A/W/X/Y/Z/file1
A/W/file1
A/W/X/file1
A/file3
A/B/C/file1
A/W/X/Y/file1
A/B/file2
Run Code Online (Sandbox Code Playgroud)

预期产出

A/file1
A/file2
A/file3

A/B/file1
A/B/file2

A/B/C/file1

A/B/C/D/file1
A/B/C/D/file3


A/W/file1

A/W/X/file1

A/W/X/Y/file1

A/W/X/Y/Z/file1
Run Code Online (Sandbox Code Playgroud)

尝试编码如下,结果没有按预期进行

import sys,os
d1,d2 = '',''
l1 = [ x for x in open(sys.argv[1])]
s2 = sorted(l1,key = lambda x : len(x.split('/')))
for linE in s2:
    f1 = linE.strip('\n')
    d1 = os.path.dirname(f1)
    if d1 != d2 : print
    d2 = d1
    print linE,
Run Code Online (Sandbox Code Playgroud)

电流输出

A/file1
A/file2
A/file3

A/B/file1
A/B/file2

A/W/file1

A/B/file2

A/W/X/file1 …
Run Code Online (Sandbox Code Playgroud)

python sorting file hierarchy

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

在unix中的特定事件的引号之间提取字符串

输入文件

..
set name "old name"; # comment "should be updated"
..
Run Code Online (Sandbox Code Playgroud)

输出文件

..
set name "new name" ; #comment "should be updated"
..
Run Code Online (Sandbox Code Playgroud)

当我试图grep -i 'name' inputfile | grep -P \".+{\"} 在第一个"和最后一个"之间的grepping内容之间grep引号 之间的内容

old name"; # comment "should be updated

任何使用的想法grep,sed或者awk!

regex unix awk grep sed

4
推荐指数
2
解决办法
2万
查看次数

如何根据键的值对TCL数组进行排序?

INITIAL_ARRAYIS

Key -> Value
B      8
C     10
A      5
E      3
D      1
Run Code Online (Sandbox Code Playgroud)

为了获得基于密钥的排序数组,我使用

set sorted_keys_array [lsort [array names INITIAL_ARRAY]]
Run Code Online (Sandbox Code Playgroud)

得到输出

Key -> Value
A     5
B     8
C     10
D     1
E     3
Run Code Online (Sandbox Code Playgroud)

同样明智的是,如何根据键的获得一个排序的tcl数组,如下面的输出?

Key -> Value
 C     10
 B     8 
 A     5
 E     3
 D     1
Run Code Online (Sandbox Code Playgroud)

arrays sorting tcl

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

如何将文件的内容插入perl/shell中的另一个文件(如果是regexp)

File1 Contents:

line1-file1      "1" 
line2-file1      "2"
line3-file1      "3" 
line4-file1      "4" 

File2 Contents:

line1-file2     "25"  
line2-file2     "24"  
Pointer-file2   "23"  
line4-file2     "22" 
line5-file2     "21"
Run Code Online (Sandbox Code Playgroud)

执行perl/shell脚本后,

File 2 content should become

line1-file2     "25"  
line2-file2     "24"  
Pointer-file2   "23" 
line1-file1      "1" 
line2-file1      "2"
line3-file1      "3" 
line4-file1      "4"  
line4-file2     "22" 
line5-file2     "21"
Run Code Online (Sandbox Code Playgroud)

即在包含行的"指针"之后,将文件1的内容粘贴到文件2中.

谢谢

regex shell perl insert paste

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

标签 统计

awk ×2

regex ×2

sed ×2

shell ×2

sorting ×2

unix ×2

arrays ×1

file ×1

grep ×1

hierarchy ×1

insert ×1

paste ×1

perl ×1

python ×1

tcl ×1

tcsh ×1

vim ×1