I have an CSV file which looks like this:
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),
And I want to replace every empty CSV value with NULL. Therefor I'm using sed:
sed -r 's;^,|,$;NULL,;g
:l
s;,,;,NULL,;g
t l'
Which creates this:
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,
Which is nearly what I want. The problem is that in the last line it adds NULL after de:Possen (Sondershausen) which is not what I want. Can someone tell me what is wrong with my sed command?
You can use this sed to replace all ,, with NULL or if , is at start, using a recursive label:
sed 's/^,/NULL,/; :a;s/,,/,NULL,/g;ta' file
This will not add NULL after trailing , in each line.
Output:
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),
I know the question wasn't tagged for awk, but for reference, here is a script doing the job:
awk -F, -v OFS=',' '{for(i=1;i<NF;i++) if(!$i)$i="NULL"}1' file
-F, -v OFS=',' set the input and output delimeter to ,, aka field separator.
for(i=1;i<NF;i++) is iterating through all fields except the last one.
if(!$i)$i="NULL" is setting the parameter to the string "NULL" if the parameter is empty.
The 1 at the end of the command is default action in awk: print the whole line.
This awk script will also do the same job
awk 'BEGIN{FS=",";OFS=","}
{
for(i=1;i<=(NF-1);i++)
{
if($i == ""){
$i="NULL"
}
}
print
}' file
Output
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),
What happens here
In the for-loop,we iterate through each field using the delimiter ,
If any field is empty ie if($i == "") we assign the field to null
Since csv file ends with , we don't have to process the last record, so the for loop has i<=(NF-1)