Solved

Replace CR in fields with 'nothing'

Posted on 2014-02-14
8
212 Views
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:

abcdefg^M
123456789

Desired result will be one line as:

abcdefg123456789

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!
0
Comment
Question by:sevior
  • 3
  • 2
  • 2
8 Comments
 
LVL 26

Assisted Solution

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

Author Comment

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

Thank you.
0
 

Author Comment

by:sevior
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?

Regards
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Assisted Solution

by:pony10us
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
or
sed -i -e 's/^M//g' old_file > new_file
0
 
LVL 37

Accepted Solution

by:
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?
0
 

Author Comment

by:sevior
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.
CR-replacement.rtf
0
 
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>?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

919 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

22 Experts available now in Live!

Get 1:1 Help Now