Solved

unix2dos and vi

Posted on 1998-10-27
7
974 Views
Last Modified: 2008-02-01
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
Comment
Question by:Pakman
  • 3
  • 3
7 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 2007586
:.,$ !awk '{print $0,"\r"}'
0
 

Author Comment

by:Pakman
ID: 2007587
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
 
LVL 84

Expert Comment

by:ozo
ID: 2007588
awk '{print $0 "\r"}'
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007589
Oops, I forgot that , adds a space too. Thanks ozo.
0
 

Author Comment

by:Pakman
ID: 2007590
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007591
:.,$ !awk '{print $0 "\r"}'

see the initial colon
0
 

Author Comment

by:Pakman
ID: 2007592
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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now