当我试图删除连续的重复行
awk "!x[$0]++" file
它的报道 x[: Event not found.
甚至同样的情况
sed -i -e "$!N; /^\(.*\)\n\1$/!P;D" file 以及报告
N: Event not found.
我也试过单引号,但没有帮助
任何想法来解决这些问题
示例输入文件
+--------------------+---------+---------
| 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)
有人能帮忙吗
谢谢
输入文件包含文件路径列表.建议算法做下面的层次排序输出
输入
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) 输入文件
..
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!
该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) 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中.
谢谢