- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: control M characters
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
Forums
Discussions
Discussions
Discussions
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
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-30-2007 10:55 PM
05-30-2007 10:55 PM
I wanna check if a file contains control M [^M]
characters in it.
Not a perl script, but a shell script solution.
Can I check for it
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2007 11:09 PM
05-30-2007 11:09 PM
Re: control M characters
Otherwise you can use grep but you'll have problems getting a control M into the shell.
I was able to use control V, then control M in vi to get:
$ fgrep -q ^M file
- Tags:
- dos2ux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2007 11:35 PM
05-30-2007 11:35 PM
Re: control M characters
try:
find . -type f |xargs grep -l ^M
Where the ^M character should be typed as:
ctrl+v ctrl+m
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2007 11:53 PM
05-30-2007 11:53 PM
Re: control M characters
dint work..
I have attached the file.
You can test this file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 12:02 AM
05-31-2007 12:02 AM
Re: control M characters
dint work.
Works fine for me using a real shell. As I said, you have to create a script with control M. You can't enter it directly to the shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 12:04 AM
05-31-2007 12:04 AM
Re: control M characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 01:00 AM
05-31-2007 01:00 AM
Re: control M characters
What's (?) so hard with:
# perl -ne 'print if /\015/' file
THe \015 is the octal code for a Carriage-Return which is graphically seens as ^M. The Perl snippet reads every line of a 'file' passed printing any line that has a carriage-return in it.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 02:18 AM
05-31-2007 02:18 AM
Re: control M characters
grep -f P1
or for all Control characters, try
grep [:ctrl:]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 02:33 AM
05-31-2007 02:33 AM
Re: control M characters
# grep -q ^M infile && echo "Ctrl M chars found" || echo "No Ctrl M chars found"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 02:50 AM
05-31-2007 02:50 AM
Re: control M characters
Sandman, your solution occurred to me also, but when i tried it in ksh on 11.0, entering that key sequence generated a Ctrl-J on the command line. Suspect its an issue w/ "set -o vi" / .exrc / .kshrc, but didn't check further...just proceeded on in a different direction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 03:46 AM
05-31-2007 03:46 AM
Re: control M characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 03:59 AM
05-31-2007 03:59 AM
SolutionIf testing a shell variable then:
echo "${MYVAR}" | grep -q $(echo "\r\c")
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "CR Found"
fi
If testing a file:
grep -q $(echo "\r\c") infile
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "CR Found"
fi
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 07:36 AM
05-31-2007 07:36 AM
Re: control M characters
I kept saying that. But vi allows ^M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2007 08:18 PM
05-31-2007 08:18 PM
Re: control M characters
grep [\015] file
it's ok on my Hp-UX 11i
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2007 07:39 PM
06-01-2007 07:39 PM
Re: control M characters
I almost took you at your word since I didn't check this. (I forgot what Ronnie said. ;-)
But now I did and this does not work in a real shell. What shell did you use?
A similar (but quoted) syntax works in tr(1): "[\015]"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2007 01:52 PM
06-03-2007 01:52 PM
Re: control M characters
#dos2ux test1 > test2
your ^M will be remove at file test2.
thanks
freddy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2007 08:32 PM
06-04-2007 08:32 PM
Re: control M characters
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "CR Found"
fi
worked fine..
thanks..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2007 08:33 PM
06-04-2007 08:33 PM
Re: control M characters
dos2ux test1 > test2
perfect command..
Thanks a lotttttt...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2007 11:28 PM
06-04-2007 11:28 PM
Re: control M characters
Just like you were informed in the very first reply a week ago!
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2007 11:37 PM
06-04-2007 11:37 PM
Re: control M characters
Exactly.
Other than Clay's echo trick, OldSchool's file of CR and JRF's perl script, nothing was added since my first reply.
(And I only got 4 points. Though Rinky can add some more. ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2007 12:08 AM
06-05-2007 12:08 AM
Re: control M characters
"I wanna check if a file contains control M [^M] characters in it."
Na Zdrave
(Bulgarian Cheers!)
yogeeraj