我在尝试着:
0 0 0
到文件的第一行。2*pi
或6.2832
乘以三列文件的第一列,其格式类似于下面,但前提是该行以数字开头。第二列和第三列保持原样。*
如果行不以数字开头,则在行首附加a(除非它已经是 ) *
。即只是注释掉当前行,除非它已经被注释掉了。这是一个示例输入文件:
* radius, section, index
1.12 A 0
2.0 A 1
* There is white space before this comment
* This is a comment indicating a new section
5 B 0
3.17 B 1
7.3 B 7
This row starts with an alphabet char and should be commented out by the script.
0 C 1
1 C 2
Run Code Online (Sandbox Code Playgroud)
这是预期的输出:
0 0 0
* radius, …
Run Code Online (Sandbox Code Playgroud) 我有一个只有 2 列(但有很多行)的 CSV 文件,偶尔会有不规则行,这些行始终以星号 (*) 字符开头,并且可能跨越两列以上。仅使用 Linux 命令行,预期行为是:
例如,如果我有一个包含以下内容的 CSV:
0,Apple
1,Apple
2,Apple
* Checkpoint
* Another checkpoint
3,Apple
4,Apple
5,Box
6,Box
7,Citrus
8,Box
9,Apple
10,Apple
11,Apple
12,Dove
13,Citrus
* Sudden checkpoint, * Leftover checkpoint note 1, * Leftover checkpoint note N
14,Citrus
15,Citrus
16,Citrus
17,Apple
18,Citrus
Run Code Online (Sandbox Code Playgroud)
之后应该如下所示:
0,Apple
* Checkpoint
* Another checkpoint
4,Apple
5,Box
6,Box
7,Citrus
8,Box
9,Apple
11,Apple
12,Dove
13,Citrus
* Sudden checkpoint, * Leftover checkpoint note 1, * Leftover …
Run Code Online (Sandbox Code Playgroud)