LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-08-2013, 02:47 AM   #1
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Rep: Reputation: Disabled
how to find if a file is having return carriage and new line characters ?


Hi,

how can we get to know if a file is having return carriage and new line characters.
we can view the special char when we open the file in vi :set.

But please suggest me any code as i need to check more than 500 files per day.

appreciate your time.
Thanks in Advance
 
Old 01-08-2013, 03:16 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,475

Rep: Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424
have you tried the command file <filename>?
 
Old 01-08-2013, 03:50 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,006

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
One way of making sure is removing any CR's that might be there (if you are in unix that is the standard text-file format). There are many programs to do that, my favourite is this: adcr.c.
Usage:
Code:
# cc -o /usr/local/bin/adcr adcr.c
# ln -s adcr /usr/local/bin/rmcr
$ rmcr *.txt
 
Old 01-08-2013, 04:28 AM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 981
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
Use the "od" command.
 
1 members found this post helpful.
Old 01-08-2013, 07:25 AM   #5
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Thanks for your valuable time.

Im finding command od useful.
I tried it using as

Code:
od -c abc | grep "\n"
This will list all the file lines with newline character

Thanks linosaurusroot
 
Old 01-09-2013, 12:42 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
cat -A filename will display all non-printing characters, in caret notation form (except the (LF) newline, which is represented by "$").


Edit: you can list out files that have carriage returns as the last character on a line with this:
Code:
grep -l $'\r$'
It relies on the $'..' "ansi-c" quoting style, supported by bash and some other advanced shells, that expands backslash escape characters.

Last edited by David the H.; 01-09-2013 at 12:54 PM. Reason: stated
 
1 members found this post helpful.
Old 01-09-2013, 12:48 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,353

Rep: Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989
edit: answered above

Last edited by suicidaleggroll; 01-09-2013 at 12:50 PM.
 
Old 01-10-2013, 02:27 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,247

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Meta-question: do you really need to know if it has \r\n chars or do you just need to ensure files with both are converted to just \n (or vice-versa).
The unix2dos and dos2unix cmds will safely convert files that need converting and not convert files that are already correctly formatted.
 
Old 01-10-2013, 05:28 AM   #9
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Hi chrism01,

Thanks so much for your response.

I just want to detect the files with \r\n.
Im able to find it through od command.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java bufferedreader -- how to read carriage return/new line sent over network from C texasone Programming 2 01-20-2012 09:15 AM
Line feed or carriage return-linefeed? Aka \n or \r? stf92 General 10 01-20-2012 01:55 AM
Line wrap on embedded system issues carriage return but no linefeed crunchytheory Linux - Embedded & Single-board computer 4 09-18-2011 01:20 AM
Cut adding $ and carriage return characters for MAC addresses DaveQB Linux - Software 4 09-25-2009 12:39 AM
Remove New Line or Carriage return from Text File DIMonS Programming 13 10-01-2007 11:31 AM


All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration