[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

^M

Hi friends:
    I find there alway a word '^M' in my file when i ftp it to HP,I am tired about the word '^M'.How to delete '^M' from my file?
0
mingwei
Asked:
mingwei
  • 6
  • 4
  • 2
  • +2
1 Solution
 
ozoCommented:
tr -d '\015'
or ftp in ascii mode
0
 
ahoffmannCommented:
dos2ux file > newfile  # on HP

ozo, ftp in ascii mode ??
assumes that the ftp client is one of the crazy (or stupid) ones which makes changes while putting files (like M$'s)
I highly recommend not trusting such things, you may be surprised by the results, sometimes ;-)
0
 
mingweiAuthor Commented:
Thanks for your comment,but I think there must be some way to delete ^M in vi editor,can you help me again?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ahoffmannCommented:
:%s/^V^M//g

# where  ^V  means ctrl-V and ^M means return key, you will not see the ^V while input
#
# or if you have vim or similar
:set notextmode
:w
0
 
mingweiAuthor Commented:
Hi ahoffmann:
first way you tell report:
Substitute pattern match failed
second way you tell report:
not such option
0
 
ahoffmannCommented:
> Substitute pattern match failed
then you did not type it correctly

BTW, a slightly better solution
:%s/^V^M$//g
0
 
mingweiAuthor Commented:
Sorry :%s/^V^M//g
No using!
Problem just like before!
0
 
ozoCommented:
How do you know the file contains ^M?
0
 
ahoffmannCommented:
ozo, it is visible verbatim in standard vi (but not vim or alike); HP-UX uses standard vi, usually

nota bene: with "standard vi" I mean the original Berkley distribution, which is used in (all)most proprietary UNIX versions (AIX, HP-UX, IRIX, SunOS, ULTRIX, ...)
while FreeBSD, NetBSD and Linux are more likely using vim (or friends) as their default vi
0
 
bedotCommented:
replacing or deleting a string in a file can be done under vi, or sed:
IE, my file tst containing hello^M^J:

(^M is a return represented here with metacharacter \r)
# od -bc tst
0000000   h   e   l   l   o  \r  \n  \0
        150 145 154 154 157 015 012 000
0000007

^M is obtained typing ^Vreturn: ^V is an introducer of control character;  so, i can replace ^M with x
# cat tst | sed -e s/^M/x/ | od -bc
0000000   h   e   l   l   o   x  \n  \0
        150 145 154 154 157 170 012 000
0000007



if i want suppress the ^M, nothing in the second part of the explession


# cat tst | sed -e s/^M// | od -bc
0000000   h   e   l   l   o  \n
        150 145 154 154 157 012
0000006



under vi, if you want suppress all the ^M in each line, you must
typein the command line (acceded with escape : )
1,$ s/^V^M//

that will write in the command line  (^V being an introducer of control code)
1,$ s/^M//

1,$ representing from the 1st line to the last

1,100 to do from the 1st to the 100th



hope fully helpfull for you
0
 
mingweiAuthor Commented:
Thanks for your answer!That is what i wanted!
0
 
dankhCommented:
hi,

  an even easier way:

%s/^M//g
0
 
ahoffmannCommented:
dankh, small and simple not accepted :(
0
 
bedotCommented:
AHOFF, don't be so weary!
if you give a so short response at an expert, is able to understand;
it seem that minqwei is not a specialist unix: so it need a response that help him to understand: need more explanation;

You yave loss only 1 point

0
 
ahoffmannCommented:
je faƮt des blaque, tous les jours ... :-)
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 6
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now