Solved

Replace CR in fields with 'nothing'

Posted on 2014-02-14
8
215 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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, 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 37

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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…
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…

770 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