i have the file <infile> with ^M charactrer. i just wnt to know through script whether the file have ^M character or not.
Please let me know the script steps to check the same.
Thanks in Advance
Ganesh.
i have the file <infile> with ^M charactrer. i just wnt to know through script whether the file have ^M character or not.
Please let me know the script steps to check the same.
Thanks in Advance
Ganesh.
From the command line:
grep '^M' FILENAME >/dev/null && echo "DOS EOL present"
However the trick is the insertion of the ^M charachter at the command line, if you preceed it with a [Ctrl]-V the next character is read as a literal rather than (for example ^M sending a carrige return to the shell)
grep -q "^M" infile
--> use Ctrl+V then Ctrl+M to get ^M don't type ^ and M
Just a thought: If you're want to check whether the file format is dos or unix, then you may do so using the file
command too.
$ file dosfile.txt
dosfile.txt: ASCII text, with CRLF line terminators
$ file unixfile.txt
unixfile.txt: ASCII text