The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Carriage Return at end of file bd_joy Shell Programming and Scripting 14 10-20-2006 01:20 PM
Removing Carriage Return and or line feed from a file tbone231 Shell Programming and Scripting 1 02-18-2005 04:37 PM
sed removing carriage return and newline mored Shell Programming and Scripting 2 05-06-2004 12:28 PM
Removing Carriage return to create one record r1500 Shell Programming and Scripting 3 02-06-2004 03:45 PM
Removing carriage return characters from file b1saini UNIX for Dummies Questions & Answers 3 09-10-2003 09:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2008
sirahc sirahc is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Issue with Removing Carriage Return (^M) in delimited file

Hi - I tried to remove ^M in a delimited file using "tr -d "\r" and "sed 's/^M//g'", but it does not work quite well. While the ^M is removed, the format of the record is still cut in half, like
a,b, c
c,d,e

The delimited file is generated using sh script by outputing a SQL query result to tab delimited file. The ^M embedded in the record is captured from user input, I believe.

Any insight is appreciated.
  #2 (permalink)  
Old 03-19-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question Can you provide a hex or octal dump of the file?

Or at least the first few lines of data?

try something like the following which will look at the first five lines:
(use your file in place of infile)

>head -5 infile | od -An -t oC -w10

Note, in octal
<CR> carriage return = 015
<LF> line feed = 012

Last edited by joeyg; 08-27-2008 at 11:23 PM.. Reason: removed an extra dash in command
  #3 (permalink)  
Old 03-19-2008
sirahc sirahc is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Re: Can you provide a hex or octal dump of the file?

Hi joeyg,

Thanks for your reply. Unfortunately, this is sensitive data so I can't send out a dump. I did use the od command to pull the data and checked for \r (od -c). I see that there is carriage return (\r)+ new line control (\n) embedded in the record.

When I used tr -d "\r\n" , however it remove all line breaks with just "\n". Do you know how I can remove only the string "\r\n" without touching those with only "\n"?

Thanks,
sirahc
  #4 (permalink)  
Old 03-20-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question Without a sample file, I am just thinking...

How about something like:

Code:
infile="original.dat"
outfile="revised.dat"
while read zf
  do
    printf "$zf\n" >>$outfile
done < $infile
  #5 (permalink)  
Old 03-20-2008
kanu_kanu kanu_kanu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
how abt dos2ux / dtox command ?
  #6 (permalink)  
Old 03-21-2008
sirahc sirahc is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Thansk for all your suggestions

Thanks for all your suggestions. The printf/dos2unix commands did work to some extend but cause format problem to other columns. I eventually used SQL to remove ^M before outputting it to the file.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0