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 Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Issue with Removing Carriage Return (^M) in delimited file sirahc UNIX for Advanced & Expert Users 7 03-25-2008 05:08 AM
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

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 09-09-2003
b1saini b1saini is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 2
Question Removing carriage return characters from file

Hello there,

I need to remove carriage return characters (\n and \r) from any input file specified. This is what I am doing right now:

- dumping the file to octal format using the command 'od -c file_name
- removing and \s and \n characters using sed commands

What I need to do now is convert the file_name from octal format back to a normal format. By normal I mean without octal numbers everywhere.

Please advise on how to undo a conversion done by using the 'od' command.

OR - if you have a better way of removing carriage return characters then please let me know.

Regards,
  #2 (permalink)  
Old 09-09-2003
andyj andyj is offline
Registered User
  
 

Join Date: Jul 2003
Location: UK
Posts: 27
try this C

$vi nonewlines.c
Code:
#include <stdio.h> 
/*nonewlines.c - remove nl and cr */
main()
{
int ch;
      while((ch = getchar()) != EOF) if ((ch!='\n')&&(ch!='\r')) putchar(ch);
}
cc nonewlines.c -o nonewlines

./nonewlines < filetochange
  #3 (permalink)  
Old 09-09-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Please use the search function before posting. We get this question several times a month. Here are a few threads...


there was a strange character(^M) been added automatically in UNIX

^m

getting rid of control characters

Porting of Windows written unix scripts to unix platform
  #4 (permalink)  
Old 09-10-2003
b1saini b1saini is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 2
Talking Thanks

Thanks for the input guys. I ended up using

cat filename | tr -d "\r \n" > filename2

Worked great.
Sponsored Links
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 10:19 PM.


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