1833752 Members
2673 Online
110063 Solutions
New Discussion

Re: vi questions

 
SOLVED
Go to solution
wvsa
Regular Advisor

vi questions

Greetings all, have a couple of questions regarding vi, first isn't there a way to display the control characters in a file created by vi. Would like to display the carriage return values.

Second question, a couple of the developers are saying their ctrl-M represents linefeed instead of carriage return. Have looked in their .profile and .exrc. Is there another place I should be looking? Thankyou in advance for you assistance.
9 REPLIES 9
Joseph C. Denman
Honored Contributor

Re: vi questions

Hi wvsa,

Not sure how to make vi show newlines? However, the dev are somewhat correct about the ^M. The ^M is a linefeed charater. This comes about most of the time when transfering ascii files from a windows system to a unix system. Windows systems use linefeed vs newline used by unix systems. You can correct this buy running dos2ux on the files. man dos2ux.

Also tell your dev when ftping ascii file to always transfer them as ascii. ftp will automatically do the translation for you.


Hope this helps.

...jcd...
If I had only read the instructions first??
Christopher McCray_1
Honored Contributor

Re: vi questions

1) You would use :set list to display tabs end of lines, spaces, etc. You can also issue the following :

#cat -vet
will produce the same results (read-only)

2) ^M is in fact the carriadge return, not line feed. Look in "UNIX in a Nutshell" by O'Reilly.

Hope this helps
Chris
It wasn't me!!!!
harry d brown jr
Honored Contributor

Re: vi questions


:set list

will display "control characters"

To remove extra "control M's" do this, from vi, although there are other external ways:

:s///g99999

It will display :s/^M//g99999


live free or die

harry

Live Free or Die
harry d brown jr
Honored Contributor
Solution

Re: vi questions

If you want to see "all" of the control characters, at the command line, use:

od -bc - shows charactersand their octal equiv

or

od -xc - shows changers and their hex equiv

live free or die
harry
Live Free or Die
Darrell Allen
Honored Contributor

Re: vi questions

Hi,

Developers are wrong. ^M is a carriage return. ^J is a line feed or in UNIX a newline. Verify this with man ascii.

When UNIX sees ^J it is interpreted as advance one line and return cursor to the leftmost column. DOS only interprets ^J as advance one line (as if you manually turned the platen on a typewriter). DOS needs an ^M to move the cursor to the leftmost column.

So one should always ftp ascii files in ascii mode because a function of ftp is the translation of ^J^M for DOS to just ^J for UNIX. dos2ux does the same thing to a file if it was transferred in binary mode.

If you just cat the file, extra ^M characters are not seen. It's just as if you are moving the cursor to the leftmost position and doing it again. vi or od will show the extra characters.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
James R. Ferguson
Acclaimed Contributor

Re: vi questions

Hi:

Have a look at 'man 5 ascii'. Not only are the displayed graphics shown, but the keyboard sequences for generating them are given.

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: vi questions

This is a common FAQ...and it occurs solely because users are either:

1. transfering files using ftp between a PC and Unix but using BINARY rather than ASCII transfers for true ASCII files.

2. Users are sharing PC files using CIFS/9000 (or SAMBA) and the native file formats will not be translated in a disk share.

Here's the issue: DOS/Windows defines plain ASCII file lines as while Unix systems (long before DOS/Windows) defined ASCII file lines as . So there is a problem going either way.

In DOS/Windows, a true Unix file will look messed up in Notepad (a true ASCII editor) since at the end of each line is a black square (the Unix character, also known as the end-of-line terminator).

In Unix, a DOS/Windows file will have an extra character at the end of each line (the character) and this shows up in vi, cat and xd as ^M, also known as CTRL-M which is really the Carriage Return character.

HP-UX command writers realized a long time ago that this would be a problem and created the two translation programs: dos2ux and ux2dos. They elimnate the need for sed/awk/tr scripts to filter these files in either direction. Check the man pages.

And ftp designers were quite smart in defining a format-neutral way of transmitting ASCII files that would let the recipient prepend/append whatever codes are necessary to form a valid ASCII file on the target system--just use ASCII as the translation method. BINARY transfers turn off all translation.

Note that Wordpad and Word4Windows will seem to accept un-translated Unix files correctly, and indeed, you can cut and paste from WordPad or Word into Notepad and get the right results. However, both WordPad and Word define a single character as a 'soft' carriage return which means something to their internal formatting procedures and will provide unexpected surprises later.


Bill Hassell, sysadmin
Anonymous
Not applicable

Re: vi questions

with respect to your first q:
:set list
vi shows special characters eg
lf is $
cr is ^M
as described in man ascii

Cheers, Thomas:)
PS: you may also want to have a look at man xd