Solved

Replace CR in fields with 'nothing'

Posted on 2014-02-14
8
222 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 38

Accepted Solution

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

Assisted Solution

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

730 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