• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1028
  • Last Modified:

unix2dos and vi

I need to be able to perform the equivalent of the unix2dos command from within vi. Among several failed attempts, here is one:
      :.,%s/\(.*\)/\1^M/g
where ^M is actually ^V^M

Incidentally, I got dos2unix working fine by doing:
      :.,%s/^M//g
Any ideas on unix2dos? The actual program is messed up on my system and I'd much rather be able to do it by hand with a simple global replacement.
0
Pakman
Asked:
Pakman
  • 3
  • 3
1 Solution
 
ahoffmannCommented:
:.,$ !awk '{print $0,"\r"}'
0
 
PakmanAuthor Commented:
That results in each line ending with a space, then the carriage return. How can a 1-liner result in just the carriage return?
0
 
ozoCommented:
awk '{print $0 "\r"}'
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
ahoffmannCommented:
Oops, I forgot that , adds a space too. Thanks ozo.
0
 
PakmanAuthor Commented:
Not to be picky (maybe I'm using it wrong), but I am using this command (from the shell) to redirect to a temp file, then renaming the temp as original. Is there an easier way? How would you use that awk command from within the vi session?
0
 
ahoffmannCommented:
:.,$ !awk '{print $0 "\r"}'

see the initial colon
0
 
PakmanAuthor Commented:
Got it to work. I must mention, however, that the following will do it for all lines (instead of from the current line till the end as the proposed answer indicates):
              :%!awk '{print $0 "\r"}'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now