DEV Community

Michael
Michael

Posted on • Originally published at gbase.cn

Fixing Database Import Failures After Moving Text Files from Windows to Linux

A common pitfall when moving text files from Windows to Linux for database loading is the difference in line endings. Tools like load or dbload can choke on the extra carriage return characters that Windows inserts.

Root Cause

  • Windows terminates lines with \r\n (carriage return + line feed). Linux uses only \n (line feed).
  • The leftover \r appears as a ^M character on Linux and breaks the expected data format, causing import failures.

How to Detect the Problem

Use cat -v to check if a file contains ^M characters:

cat -v filename
Enter fullscreen mode Exit fullscreen mode

If ^M appears at the end of each line, the file has Windows‑style endings.

The Fix

Use the tr command to replace the carriage returns:

tr -s "\r" "\n" < source_file > target_file
Enter fullscreen mode Exit fullscreen mode

This reads the source file, replaces all \r characters with \n, and writes a clean, Linux‑compatible file. Once converted, your import through utilities like load or dbload into a gbase database should complete without errors.

Top comments (0)