- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- check file format (creation dos or unix)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 12:18 AM
тАО05-11-2011 12:18 AM
what is the best way to detect, if file was created in DOS with ^M .
two options:
grep -c '^M$' file
od -c file |grep '\\r \\n'
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 01:04 AM
тАО05-11-2011 01:04 AM
Re: check file format (creation dos or unix)
If the file is already in unix format, then HP-UX dos2ux won't make any conversion at all.
So you can do things like:
dos2ux unknown.txt > definitely-unix.txt
The ux2dos command works the same way.
(See for yourself: "ux2dos .profile | ux2dos | ux2dos | od -c" won't naively cause multiple \r's to be added: after the first ux2dos, the subsequent ones detect the line terminators are already in DOS form and will do nothing.)
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 01:14 AM
тАО05-11-2011 01:14 AM
Re: check file format (creation dos or unix)
@ "ux2dos .profile | ux2dos | ux2dos | od -c"
i know "ux2dos" , but i don't want to convert a file. we have an application, with only allows developed programs in unix format like shell scripts,etc...
so i want to check for "^M" and if exists , i report an error.
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 01:20 AM
тАО05-11-2011 01:20 AM
SolutionUsing 'grep' with the keyboard or 'vi' sequence to generate a carriage-return character is one way.
Using 'grep' with '\r' is not guaranteed to work in all Unix or Linux environments.
I would do something like:
# perl -nle 'BEGIN{$n=0};$n++ if m{\r$}g;END{print $n}' file
...to count the number of carriage returns.
...or better, if I wanted to rid my file of any:
# perl -pi -e 's{\r$}{}' file
Strictly speaking, a DOS file also ends with ^Z so to eliminate that too:
# perl -pi -e s{\r$}{};s{^\032$}{}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 03:02 AM
тАО05-11-2011 03:02 AM
Re: check file format (creation dos or unix)
cat -v file | fgrep -q "^M"
if [ $? -eq 0 ]; then
echo "DOS format for file"
fi
Or:
$ fgrep $(echo "\r\c") file
echo supports "\r" and other escapes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 05:06 AM
тАО05-11-2011 05:06 AM
Re: check file format (creation dos or unix)
> [...] so i want to check [...]
I'm confused. Do you want to know how to
check a file using some shell-script code, or
do you want to add code to "an application"
(about which we non-psychics know nothing),
or what?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2011 05:52 AM
тАО05-11-2011 05:52 AM
Re: check file format (creation dos or unix)
i want to check with a script, if a file includes ^M . Which is for my meaning 100 % created with DOS ( in DOS editor).
Dennis or James posted a solution for me.
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2011 03:31 AM
тАО05-12-2011 03:31 AM
Re: check file format (creation dos or unix)
what if you would just convert the input with dos2ux to a reliable format, no matter of what type it is. So you won't need to display that error message, and your application would have one more feature.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2011 05:09 AM
тАО05-12-2011 05:09 AM
Re: check file format (creation dos or unix)
The potential pitfall of relying on 'dos2ux' is one of portability. You won't find this (except?) on HP-UX.
Caveat emptor.
Regards!
...JRF...