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
rare problem -reinstalling formatting nothing is working simaich8 Linux 0 11-04-2007 02:07 AM
formatting textfile inside ksh script using awk not working tekline UNIX for Advanced & Expert Users 6 07-03-2007 01:40 AM
Substitution not working in ksh arsheshadri SUN Solaris 3 04-12-2007 11:20 PM
Substitution not working in ksh arsheshadri AIX 2 04-12-2007 07:30 AM
Var substitution in awk - not working as expected videsh77 Shell Programming and Scripting 3 01-13-2006 01:57 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 04-16-2007
ERPKEN ERPKEN is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 2
Formatting Substitution Command Not Working in vi

Unix Gurus,

I have a text file I have FTP'd to UNIX so that I can use it to load into our Baan system. When vi the file, I can see that there are formatting characters at the end of each line (^M). To get rid of these, I have read that the following should work:

:%s/^M$//g - with the ^M being the equivalent of CTRL V CTRL M

Unforutnately, when trying to type this command I can only get to the "CTRL M" before I get the error message "Substitute pattern match failed." Does anyone know why I cannot type the whole command shown above or is there something that cause the command to execute before the entire command is typed?

Thank you in advance for your feedback.
  #2 (permalink)  
Old 04-16-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Leave vi. The simplest solution is to do a dos2unix on the file that you just ftp'ed.
  #3 (permalink)  
Old 04-16-2007
jgt jgt is offline
Registered User
  
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 439
ftp

tranfer the file using ascii mode instead of binary, the carriage returns should be removed automatically.
  #4 (permalink)  
Old 04-17-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,950
Quote:
Unforutnately, when trying to type this command I can only get to the "CTRL M" before I get the error message "Substitute pattern match failed." Does anyone know why I cannot type the whole command shown above or is there something that cause the command to execute before the entire command is typed?
Am surprised, why that happens!

Definitely you would be able to do that!

I tried and it works ( I doubt the ctrl -v and ctrl - m )
  #5 (permalink)  
Old 04-17-2007
ERPKEN ERPKEN is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 2
Thanks for the Responses

Thanks Gurus! I never heard of or used DOS2UNIX so maybe I will try it sometime. I did take a look at my FTP settings and it was set on "Automatic." After changing it to "ASCII," I FTPd some files over that I had problems with in the past. Sure enough, no more problems with character formatting! I guess I assumed that "Automatic" would always give me the best method of moving the file.

I still would also be interested in knowing why I am not able to use the command %s/^M//g. The commands I am using to get the formatting character are ctrl v followed immediately by ctrl m. There is no use of the shift key, minus signs, plus signs, etc - only the ctrl button with the letter v follwed by the ctrl button and the letter m.
  #6 (permalink)  
Old 04-17-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
In VI the following works ,
:%s/^M//g

OR

Give the below ones a try,
tr -d \015 \032 < inputFile
tr -d '^M' < inputFile
sed 's/^M//g' < inputFile

Thanks
Nagarajan Ganesan
  #7 (permalink)  
Old 04-18-2007
sumitpandya sumitpandya is offline
Registered User
  
 

Join Date: Mar 2006
Location: Ahmedabad
Posts: 125
Nagarajan,
Your process is lengthy. I simply go for following
echo "foo" >> file-name
Then edit file using "vi" editor. your "^M" will be visible. Just remove that using compatible "vi" pattern-replacement method. Remember last-line "foo" and save file.

Special attention is required in above make sure you use ">>" and NOT ">" otherwise its gone.
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 01:58 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