我有一个CSV文件,如下所示:
16949839,49.5474463,8.6692215,4,31336605,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Schau- und Sichtungsgarten Hermannshof,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
17025149,49.5444114,8.6715051,2,670583,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Voliere,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
24557757,50.0550103,11.8494971,5,8289559,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1000-Meter-Stein,stone,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
25505794,50.0407824,11.8647266,5,7301040,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Nußhardtstube,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
25631399,49.8270356,11.3753338,9,39834385,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Sophienhöhle,cave_entrance,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
25932371,50.0527832,11.2319208,2,6747603,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Gaaskerng,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
26309933,50.1225540,11.3759787,2,11211206,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Staafelsn,cliff,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
26945605,49.7668812,11.4281553,7,39554170,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Großes Hasenloch,cave_entrance,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
27133657,49.6351754,8.4938556,2,1638377,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Schießbuckel,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
27133658,49.6339946,8.4853839,1,9218,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Grillhütte,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
27153008,50.1229239,11.4117973,1,7826,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Schwedenschanze,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
27374034,51.5455027,12.9933573,2,4177298,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Sommer-Rodelbahn,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
27440567,50.7319121,7.0993708,10,11317500,,,,,,,,bus_station,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Busbahnhof Bonn,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
27543115,51.8473136,12.2314568,8,19447141,,,,,,,,,,,,,,,,,,,,,,,,,,,,,building,,,,,,,,,,,Weißer Bogen,,,,,,,,,,,,,,,,,,,,attraction,,,,,,,,
28788682,51.3384522,10.8616651,9,31145828,,,,,,,,,,,,,,,,,,,,,,,430,,,,,,,,,,,,,,,,,Freizeit und Erholungpark "Zum Possen",,,,,,,,,,,,,,,,,,,,attraction,,,,,,,de:Possen (Sondershausen),
我想用NULL替换每个空的CSV值。因此我正在使用sed
:
sed -r 's;^,|,$;NULL,;g
:l
s;,,;,NULL,;g
t l'
创造了这个:
16949839,49.5474463,8.6692215,4,31336605,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schau- und Sichtungsgarten Hermannshof,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
17025149,49.5444114,8.6715051,2,670583,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Voliere,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
24557757,50.0550103,11.8494971,5,8289559,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1000-Meter-Stein,stone,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25505794,50.0407824,11.8647266,5,7301040,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Nußhardtstube,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25631399,49.8270356,11.3753338,9,39834385,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Sophienhöhle,cave_entrance,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25932371,50.0527832,11.2319208,2,6747603,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Gaaskerng,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
26309933,50.1225540,11.3759787,2,11211206,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Staafelsn,cliff,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
26945605,49.7668812,11.4281553,7,39554170,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Großes Hasenloch,cave_entrance,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27133657,49.6351754,8.4938556,2,1638377,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schießbuckel,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27133658,49.6339946,8.4853839,1,9218,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Grillhütte,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27153008,50.1229239,11.4117973,1,7826,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schwedenschanze,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27374034,51.5455027,12.9933573,2,4177298,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Sommer-Rodelbahn,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27440567,50.7319121,7.0993708,10,11317500,NULL,NULL,NULL,NULL,NULL,NULL,NULL,bus_station,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Busbahnhof Bonn,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27543115,51.8473136,12.2314568,8,19447141,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,building,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Weißer Bogen,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
28788682,51.3384522,10.8616651,9,31145828,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,430,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Freizeit und Erholungpark "Zum Possen",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,de:Possen (Sondershausen)NULL,
这几乎是我想要的。问题是,在最后一行,它在NULL
之后添加de:Possen (Sondershausen)
,这不是我想要的。有人能告诉我sed
命令有什么问题吗?
答案 0 :(得分:6)
您可以使用此sed
将所有,,
替换为NULL
,或使用递归标签将,
替换为开头:
sed 's/^,/NULL,/; :a;s/,,/,NULL,/g;ta' file
在每行中跟踪NULL
后,这不会添加,
。
<强>输出:强>
16949839,49.5474463,8.6692215,4,31336605,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schau- und Sichtungsgarten Hermannshof,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
17025149,49.5444114,8.6715051,2,670583,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Voliere,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
24557757,50.0550103,11.8494971,5,8289559,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1000-Meter-Stein,stone,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25505794,50.0407824,11.8647266,5,7301040,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Nußhardtstube,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25631399,49.8270356,11.3753338,9,39834385,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Sophienhöhle,cave_entrance,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25932371,50.0527832,11.2319208,2,6747603,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Gaaskerng,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
26309933,50.1225540,11.3759787,2,11211206,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Staafelsn,cliff,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
26945605,49.7668812,11.4281553,7,39554170,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Großes Hasenloch,cave_entrance,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27133657,49.6351754,8.4938556,2,1638377,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schießbuckel,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27133658,49.6339946,8.4853839,1,9218,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Grillhütte,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27153008,50.1229239,11.4117973,1,7826,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schwedenschanze,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27374034,51.5455027,12.9933573,2,4177298,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Sommer-Rodelbahn,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27440567,50.7319121,7.0993708,10,11317500,NULL,NULL,NULL,NULL,NULL,NULL,NULL,bus_station,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Busbahnhof Bonn,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27543115,51.8473136,12.2314568,8,19447141,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,building,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Weißer Bogen,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
28788682,51.3384522,10.8616651,9,31145828,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,430,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Freizeit und Erholungpark "Zum Possen",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,de:Possen (Sondershausen),
答案 1 :(得分:1)
我知道这个问题没有标记为awk
,但作为参考,这是一个完成这项工作的脚本:
awk -F, -v OFS=',' '{for(i=1;i<NF;i++) if(!$i)$i="NULL"}1' file
-F, -v OFS=','
将输入和输出范围设置为,
,即字段分隔符。
for(i=1;i<NF;i++)
正在遍历除最后一个字段之外的所有字段。
if(!$i)$i="NULL"
将参数设置为字符串"NULL"
。
命令末尾的1
是awk
中的默认操作:打印整行。
答案 2 :(得分:0)
此echo '<script>
alert ("Hi");
$( document ).on( "keydown", function ( e ) {
if ( e.which == 37 || e.which == 38 ) {
alert( "It works!" );
}
if ( e.which == 39 || e.which == 40 ) {
alert( "It works, also!" );
}
} );
</script>';
脚本也将执行相同的工作
awk
<强>输出强>
awk 'BEGIN{FS=",";OFS=","}
{
for(i=1;i<=(NF-1);i++)
{
if($i == ""){
$i="NULL"
}
}
print
}' file
这里会发生什么
16949839,49.5474463,8.6692215,4,31336605,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schau- und Sichtungsgarten Hermannshof,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
17025149,49.5444114,8.6715051,2,670583,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Voliere,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
24557757,50.0550103,11.8494971,5,8289559,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1000-Meter-Stein,stone,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25505794,50.0407824,11.8647266,5,7301040,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Nußhardtstube,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25631399,49.8270356,11.3753338,9,39834385,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Sophienhöhle,cave_entrance,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
25932371,50.0527832,11.2319208,2,6747603,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Gaaskerng,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
26309933,50.1225540,11.3759787,2,11211206,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Staafelsn,cliff,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
26945605,49.7668812,11.4281553,7,39554170,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Großes Hasenloch,cave_entrance,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27133657,49.6351754,8.4938556,2,1638377,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schießbuckel,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27133658,49.6339946,8.4853839,1,9218,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Grillhütte,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27153008,50.1229239,11.4117973,1,7826,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Schwedenschanze,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27374034,51.5455027,12.9933573,2,4177298,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Sommer-Rodelbahn,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27440567,50.7319121,7.0993708,10,11317500,NULL,NULL,NULL,NULL,NULL,NULL,NULL,bus_station,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Busbahnhof Bonn,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
27543115,51.8473136,12.2314568,8,19447141,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,building,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Weißer Bogen,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
28788682,51.3384522,10.8616651,9,31145828,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,430,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Freizeit und Erholungpark "Zum Possen",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,attraction,NULL,NULL,NULL,NULL,NULL,NULL,de:Possen (Sondershausen),
中,我们使用分隔符for-loop
,
,我们将该字段指定为空if($i == "")
结尾,我们不必处理最后一条记录,因此for循环有,