Formatting Substitution Command Not Working in vi


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Formatting Substitution Command Not Working in vi
# 1  
Old 04-16-2007
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  
Old 04-16-2007
Leave vi. The simplest solution is to do a dos2unix on the file that you just ftp'ed.
# 3  
Old 04-16-2007
ftp

tranfer the file using ascii mode instead of binary, the carriage returns should be removed automatically.
# 4  
Old 04-17-2007
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  
Old 04-17-2007
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  
Old 04-17-2007
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  
Old 04-18-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parameter substitution is not working with sed

I am trying add a prefix variable(string) to command output. sed parameter substitution is not working. - I have found some issues on my end of testing,, please delete this thread for now. (1 Reply)
Discussion started by: kchinnam
1 Replies

2. Shell Programming and Scripting

Simple Variable substitution in ksh not working

Hi Gurus, Not able to catch what's going wrong here. I just want to get output as "tree". server:/mk/app/nexapp $ echo $SHELL /usr/bin/ksh server:/mk/app/nexapp $ export db_name1="tree" server:/mk/app/nexapp $ export i=1 1st try: server:/mk/app/nexapp $ echo $(db_name$i) ksh: db_name1: ... (3 Replies)
Discussion started by: mukesh.lalwani
3 Replies

3. Shell Programming and Scripting

Bad substitution error while working with substring

Hi I'm using ksh. And i'm trying to get the substring like below. but giving the following error #!/bin/ksh foo=teststring bar=${foo:0:5} echo $bar And the error is ./sbstr_test.sh: bar=${foo:0:5}: bad substitution what is wrong in this script. Please correct me ... (3 Replies)
Discussion started by: smile689
3 Replies

4. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

5. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

6. Linux

rare problem -reinstalling formatting nothing is working

i am not able to install solaris 10 i have installed solaris many times succesfully with wotking network after that abrupt power failure i was never able to start solaris and neither install during install it hangs IS IT PROBABLE THAT BIOS OR SOME OTHER SETTINGS RELATED TO HARDWARE IS... (0 Replies)
Discussion started by: simaich8
0 Replies

7. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies

8. Solaris

Substitution not working in ksh

Hi, Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution... (3 Replies)
Discussion started by: arsheshadri
3 Replies

9. AIX

Substitution not working in ksh

Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution is not... (2 Replies)
Discussion started by: arsheshadri
2 Replies

10. Shell Programming and Scripting

Var substitution in awk - not working as expected

countA=`awk '/X/''{print substr($0,38,1)}' fName | wc -l` countB=`wc -l fName | awk '{print int($1)}'` echo > temp ratio=`awk -va=$countA -vc=$countB '{printf "%.4f", a/c}' temp` After running script for above I am getting an error as : awk: 0602-533 Cannot find or open file -vc=25. The... (3 Replies)
Discussion started by: videsh77
3 Replies
Login or Register to Ask a Question