使用sed命令
how can I replace \N with NULL
How can I replace the empty space || with NULL.
|200|0||0|\N||^A|0|\N||
期望的输出
|200|0|NULL|0|NULL|NULL|^A|0|NULL|NULL|
您需要稍微修改这个的版本。以下是适用于GNU sed的示例:
sed ':a; s:|\(\\N\)\?|:|NULL|:g; ta'
sed -e ':a' -e 's:|\(\\N\)\?|:|NULL|:g' -e 'ta'
tr \\n \\0
<file sed 's/\\N/NULL/g' | awk -F\| '{for(i=2;i<=NF;i++){ if($i==""){ printf "|NULL"} else{ printf "|%s", $i}}; printf "|\n"}'
使用 awk
awk 'gsub("\\\\N","NULL");gsub("\\|\\|","|NULL|")' temp.txt
sed -i 's/ /NULL/g' temp.txt
这将把任何空格字符替换为NULL
。