+2 votes
in Operating Systems by (71.8k points)
I have created CSV files by downloading data from MQ SQL server tables. When I tried to load the CSV files to PostgreSQL, it complained about the null character (x'00') and newline (\r\n) . I am using Python code to replace these bad characters, which seems a bit slow. How can I remove those characters using a Linux command?

1 Answer

+1 vote
by (353k points)
selected by
Best answer

Try 'tr' command with -d option.

Usage: tr [OPTION]... SET1 [SET2]
Translate, squeeze, and/or delete characters from standard input, writing to standard output.
  -d, --delete            delete characters in SET1, do not translate


tr -d '\000\r'   < cost/COST.csv > COST_n.csv