Replace CR in fields with 'nothing'

Posted on 2014-02-14
Last Modified: 2014-07-22
Hello experts -

question for you:

How I do replace CRLF in UNIX file (AIX OS) with 'nothing'? Example, as file fragment shows in vi:


Desired result will be one line as:


I am looking for the solution like:

sed 's/"CRLF"//g' old_file > new_file, that allows me do bulk replacement of all occurrences   of CR-LF in existing 'old_file'. ("CRLF" pattern in sed example is illustration only).
Also, it isn't DOS-to-UNIX conversion. These CRLF got into files that are 'spools' out of Oracle sqlpus when data has CR characters in VARCHAR2(..) columns.

Thank you!
Question by:sevior
  • 3
  • 2
  • 2
LVL 26

Assisted Solution

pony10us earned 250 total points
ID: 39859851
sed -e '/^M/d' old_file > new_file

Author Comment

ID: 39859863
Seems that this syntax is what I needed,
I'll update after few more test.

Thank you.

Author Comment

ID: 39860061
Well, it did work, brought number of rows in file to what it should be, but...
it messed up delimiter (which is hex 0x01).
Any comments? Or, there is other way of cleaning CRLF?

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

LVL 26

Assisted Solution

pony10us earned 250 total points
ID: 39860099
sed -i -e '/^M/d' old_file > new_file

Or use substitution:

sed -e 's/^M//g' old_file > new_file
sed -i -e 's/^M//g' old_file > new_file
LVL 37

Accepted Solution

Gerwin Jansen earned 250 total points
ID: 39861004
Can you try this:

sed 's/\x0D\x0A$//g' old_file > new_file

This should remove CRLF only from the end of the lines in your input, not the CR in your fields.

If this doesn't work, can you post a few lines of your input file as an attachment?

Author Comment

ID: 39864759
I have not checked yet sed with HEX back on AIX machine, but I should correct my question - I want to replace CR (CR-s only) in fields. Attached example shows fragment on one record that has four CR-s (HEX 0D). As a result this one record spooled as five lines in output file. There is LF (it's on fifth line of this record that is not on this picture) at the end of each record - which is correct.
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 250 total points
ID: 39864833
>>  There is LF (it's on fifth line of this record that is not on this picture) at the end of each record - which is correct.
So delete CR's in fields and leave LF's at end of lines (records)?

Then the first comment by pony10us is doing what you're asking, you know you have to type the ^M character by pressing <CTRL>-V and then <ENTER>?

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now