Solved

Script to change CR LF to LF -- 0D 0A  to 0A

Posted on 2006-06-21
12
4,188 Views
Last Modified: 2013-12-26
I'm trying to get a script written to change the carrige return linefeed characters to linefeed characters

I have a file where all lines end with Hex 0D 0A  I want them to end with 0A

I tried using sed to do a search and replace - something like this:

sed -e 's/\x0D/whatever/' test.txt > test.new

Search for 0d and replace with "whatever"

I just wanted to get this working first - Anyway - sed runs without error but apparetnly can't find any 0D in my file
even though I know the hex character exists.

Thanks
0
Comment
Question by:aflat362
[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
  • 6
  • 5
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16953251
Don't reinvent the wheel, 'recode' or 'dos2unix' can do that, e.g.

dos2unix test.txt test.new

recode ibmpc..lat1 text.txt > test.new
0
 
LVL 3

Author Comment

by:aflat362
ID: 16953438
I don't have either of those executables . . .

[x67167] dbimg1:/home/x67167) dos2unix
ksh: dos2unix:  not found.
[x67167] dbimg1:/home/x67167) recode
ksh: recode:  not found.

0
 
LVL 3

Author Comment

by:aflat362
ID: 16953449
I'm running AIX 5.2 ml 4
0
Industry Leaders: 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 43

Accepted Solution

by:
ravenpl earned 125 total points
ID: 16953820
try:
cat file.txt | perl -ne 'y/\r//d; print'
0
 
LVL 3

Author Comment

by:aflat362
ID: 16953846
hmm.

I don't have perl installed.  

I'd like to get this working with the tools I have:

shell (korn, bourne or C)
awk
sed

Thanks for the posts.
0
 
LVL 3

Author Comment

by:aflat362
ID: 16953892
nevermind.  I do have perl.

This may work for me.

cat test.txt | perl -ne 'y/\r//d; print' > test.new

Can you explain what the y/\r//d;  part of this command is doing?

or point me to a reference?

Thanks
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16953905
cat file.txt | sed -e 's/\r//'
#but please verify that it in fact removes the char...
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16953925
Bots, sed and perl s/// or y///d searches for given character, then rplaces with replaement char(or removes if no replacement found
y/ab/c/d # changes each occurance of 'a' to 'c' and remoes any 'c'.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16953929
removes any 'b' character - dorry for mistake above.
0
 
LVL 3

Author Comment

by:aflat362
ID: 16953949
Ok, so for this example it searches for \r which must equate to 0D 0A and replaces it with what? null?

what's up with the "d"?

cat test.txt | perl -ne 'y/\r//d; print' > test.new

Thanks
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16954281
in fact - not really. It searched for any \r and removes. 'd' stands for delete found but not replaced characters.
For more please see: man perlop, operation 'tr' or 'y'
0
 
LVL 3

Author Comment

by:aflat362
ID: 16954647
Thanks!
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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 94
Shell script to login to remote m/c and execute commands 10 81
centeredAverage challenge 8 188
fizzArray2 challenge 1 112
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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