Sed will replace empty space with NULL

Using sed

  • how can i replace \ n with null

  • How to replace empty space || with NULL.

    |200|0||0|\N||^A|0|\N||
    

desired output

    |200|0|NULL|0|NULL|NULL|^A|0|NULL|NULL|
+5
source share
4 answers

You need a slightly modified version of this . Something like this should work:

sed ':a; s:|\(\\N\)\?|:|NULL|:g; ta'
+2
source

I think the team you are looking for may be called "tr". Try

tr \\n \\0
+1
source
cat file | sed 's/\\N/NULL/g' | awk -F\| '{for(i=2;i<=NF;i++){ if($i==""){ printf "|NULL"} else{  printf "|%s", $i}}; printf "|\n"}'
+1
source

with awk

awk 'gsub("\\\\N","NULL");gsub("\\|\\|","|NULL|")' temp.txt
0
source

All Articles