views:

52

answers:

3

I'm trying to use something in bash to show me the line endings in a file printed rather than interrupted. The file is a dump from SSIS/SQL Server being read in by a Linux machine for processing.

Is there any switches within vi, less, more, etc?

In addition to seeing the line-endings, I need to know what type of line end it is (CRLF or LF).

+2  A: 

In vi...

:set list to see line-endings.

:set nolist to go back to normal.

While I don't think you can see \n or \r\n in vi, you can see which type of file it is (UNIX, DOS, etc.) to infer which line endings it has...

:set ff

Ryan Berger
Thank you - this has indeed worked - now I'm trying to tell if it's a \n or \r\n is there an additional switch for that in Vi?
Marco Ceppi
Unfortunately, I don't think vi can show those specific characters. You can try od -c <filename> which I believe will display \n or \r\n.
Ryan Berger
+1  A: 

In the bash shell, try cat -v <filename>. This should display carriage-returns for windows files.

(This worked for me in rxvt via Cygwin on Windows XP).

warriorpostman
+1  A: 

You can use the file utility to give you an indication of the type of line endings.

Unix:

$ file testfile1.txt
testfile.txt: ASCII text

"DOS":

$ file testfile2.txt
testfile2.txt: ASCII text, with CRLF line terminators

To convert from "DOS" to Unix:

$ dos2unix testfile2.txt

To convert from Unix to "DOS":

$ unix2dos testfile1.txt

Converting an already converted file has no effect so it's safe to run blindly (i.e. without testing the format first) although the usual disclaimers apply, as always.

Dennis Williamson