?
Solved

Replace CR in fields with 'nothing'

Posted on 2014-02-14
8
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
8 Comments
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 1000 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 1000 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 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1000 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 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 1000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
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.
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 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