LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2002, 05:53 PM   #1
Silly22
LQ Newbie
 
Registered: Mar 2002
Location: Edmonton, AB
Distribution: Mandrake 10.2, Ubuntu 6.10
Posts: 26

Rep: Reputation: 15
Need help with Regular Expressions and Hexadecimals


I'm using VIM and I have a screwy html file.
It is in Unix format... but a stupid piece of crap Microsoft program added a bunch of carriage returns CR to it. Most of the lines are ended with a CR + LF but the microcrap proggy added an extra CR to some lines.

I just want to search and replace the lines using regular expressions in VIM. But the search fails whenever it encounters the crap that micro$oft put in.

Here's what it looks like in both ascii and hex.

<p>
<pre>

here's the hex stuff that you can't see (btw 0d = CR, 0a = LF)

<p>0d 0a 0d
<pre>

the extra '0d' at the end was inserted by the micro$oft program. Normal Unix files have just 0d 0a to end and start a line.

the regex command i used in ViM to try to find it was:
/<p>(.|\n)*<pre>

but it fails to find the pattern... therefore I can't use a regex substitution expression on it. (plan to do it on multiple files)

Does anyone know how to use the \x hexadecimal character class that Vim's regex comes with?
 
Old 06-04-2002, 06:09 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
can you not just use dos2unix or something similar?
 
Old 06-04-2002, 06:53 PM   #3
tyler_durden
Member
 
Registered: May 2001
Posts: 125

Rep: Reputation: 15
i am pretty sure that you can open it in pico and it will remove them then just save it
 
Old 06-04-2002, 07:56 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
When I usually vim a windows formatted text file I see the "^M" character at the end of the line. I'm not sure why you do not see that. I use the command ":s/^V^M//g" to get rid of the windows crap. Note that the <ctrl>V will not appear, it just allows you to enter the <ctrl>M correctly.
 
Old 06-05-2002, 06:51 AM   #5
vfs
Member
 
Registered: Apr 2002
Location: Brazil
Distribution: Slackware
Posts: 184

Rep: Reputation: 30
try:

cat file | tr -d '\r'

or

fromdos < file.dos > file.unix


hth

vfs
 
Old 06-05-2002, 10:08 AM   #6
Silly22
LQ Newbie
 
Registered: Mar 2002
Location: Edmonton, AB
Distribution: Mandrake 10.2, Ubuntu 6.10
Posts: 26

Original Poster
Rep: Reputation: 15
Thanks for all the excellent help.

I found out that I was just using the OR '|' pipe incorrectly in vim. Didn't know i had to escape the pipe using \I

So my Vim regular expression search command was:
<p>\(.\|\n\)*<pre>

Vim has that magic and nomagic thing that confuses me since I use other regular expression programs.

Anyway, the above found all the extra '0d' CR's that the micro$oft program put in.

Thanks for that neat trick crabboy, with the <ctrl>+V and <ctrl>+M. That worked too.
the search pattern was <p>\(\n\|^M\)*<pre>
Using the ^V^M thing.
 
  


Reply



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
Regular Expressions markjuggles Programming 2 05-05-2005 11:39 AM
Regular Expressions overbored Linux - Software 3 06-24-2004 02:34 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 10-31-2003 11:09 PM
Regular expressions aromes Linux - General 1 10-15-2003 12:29 PM
regular expressions? alaios Linux - General 2 06-11-2003 03:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:33 AM.

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
Open Source Consulting | Domain Registration