View line-endings in a text file
View line-endings in a text file
I'm trying to use something in bash to show me the line endings in a file printed rather than interpreted. 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).
Answer by Ryan Berger for View line-endings in a text file
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
Answer by warriorpostman for View line-endings in a text file
In the bash shell, try cat -v
. This should display carriage-returns for windows files.
(This worked for me in rxvt via Cygwin on Windows XP).
Editor's note: cat -v
visualizes \r
(CR) chars. as ^M
. Thus, line-ending \r\n
sequences will display as ^M
at the end of each output line. cat -e
will additionally visualize \n
, namely as $
. (cat -et
will additionally visualize tab chars. as ^I
.)
Answer by Dennis Williamson for View line-endings in a text file
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.
Answer by Zorayr for View line-endings in a text file
You may use the command todos filename
to convert to DOS endings, and fromdos filename
to convert to UNIX line endings. To install the package on Ubuntu, type sudo apt-get install tofrodos
.
Answer by Rich for View line-endings in a text file
You can use xxd
to show a hex dump of the file, and hunt through for "0d0a" or "0a" chars.
You can use cat -v
as @warriorpostman suggests.
Answer by P. Kucerak for View line-endings in a text file
Program less is working for that; at FreeBSD 8.4, man less says:
-u or --underline-special
Causes backspaces and carriage returns to be treated as print- able characters; that is, they are sent to the terminal when they appear in the input.
-U or --UNDERLINE-SPECIAL
Causes backspaces, tabs and carriage returns to be treated as control characters; that is, they are handled as specified by the -r option.
And read further..
If you use less -u, you can see CR at end of line as ^M.
Answer by Diego for View line-endings in a text file
I dump my output to a text file. I then open it in notepad ++ then click the show all characters button. Not very elegant but it works.
Answer by Alex Sh for View line-endings in a text file
Ubuntu 14.04:
simple cat -e
works just fine.
In case you wondered - '$' (a dollar sign) is a newline symbol in cat -e
output
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71
0 comments:
Post a Comment