'^m' character at end of lines
Banish the ^M
(carriage return - CR
) from SQL strings with REPLACE
:
CHAR(13)
pinpoints the ^M
fiend; firing off a REPLACE
on my_column
sends it packing.
Investigating the '^M' mystery
Those sneaky ^M
characters you're spotting at line ends are carriage returns hailing from the DOS/Windows neck of the woods, where line boundaries are outlined by a carriage return (CR) trailed by a line feed (LF), depicted as \r\n
. In contrast, Unix systems prefer the minimalist approach and use a solitary line feed (LF), represented as \n
, for line cutoffs. When a DOS/Windows borough file (CR + LF) embarks on a Unix excursion, the CR
pulls a 007 and masquerades as ^M
.
Juggling different environments
Tweaking file formats in vi
or vim
like a pro:
Deploying dos2unix
like you're launching code missiles:
Remember to peruse the man-pages for dos2unix
. Knowledge is power!
Origin OS playing hide and seek:
When the birthplace OS of your script or text file eludes you, utilities like file
or hexdump
will play the detective and reveal those line-separating brutes.
The awkward tango between SQL and '^M'
Amidst the beautiful ballet of SQL database operations, the insidious ^M
character may occasionally gatecrash the party, bulldozing its way through script imports, user inputs, or unguarded data sources.
Restoring order in your SQL kingdom:
Building a '^M'-proof fortress
Getting Git to play ball:
Tweak the core.autocrlf
switch in Git to form a sturdy barrier against ^M
infiltrations into your code repository.
Manipulating IDE/editor settings:
Pull the strings of your IDE or text editor to adopt Unix-style line finales when conjuring or storing files – a lifesaver in a cross-platform cosmos.
Automation to the rescue:
Draft line-ending audits into your CI/CD pipeline team or employ pre-commit
hooks as vigilant gatekeepers to keep ^M
outside your code turf.
Was this article helpful?