GP2X Vi Help


Shikaku

ROFL THE WORD PENIS IS HILARIOUS!
Joined
Jan 11, 2006
Messages
2,839
Location
USA... I feel lonely, not that many people from US
Website
Visit site
I'm trying to go through a file in VI and delete junk that I know is between a > and a }.

<P CLASS=SUBTTL>800,0,Default,,0000,0000,0000,,{\3c&H572C1A&}I didn't forget.

Basically everything that is the bold/underline (Yes, I'm doing subtitle editing).

I can't seem the get the syntax right.

%s/>*}/>

Is one VI command that I thought would work, but I cannot do that obviously. I need just one specific thing that can allow me to do this, if it exists...

Thanks in advance
 
Shikaku posted on Feb 28 2006 at 04:35 AM said:
... I don't know sed...

... and I don't know vi. The regexp dialect may be different, but try:

Code:
 %s/\>[^\}]*\}/>

It may be that some of those symbols are regexp syntax, so to be safe escape with \. Also * works differently in regexps than in shell globs (file matching), it means 'match zero or more of the preceding character' not 'match any string of characters'. using [^\}]* means 'match any number of characters which is not a }'.

I haven't slept in a while, so that may be totally incorrect and/or incomprehensible :)
 
Last edited by a moderator:
Klepto posted on Feb 28 2006 at 02:25 PM said:
I'd consider using sed for that, a one line command should edit the file for you.

try
Code:
cat filename.html |sed -e 's/>.*}/>/' > newfile.html

Cheers,
Jonesy
http://www.haqthegibson.com
 
Last edited by a moderator:
Shikaku posted on Feb 28 2006 at 06:15 AM said:
Thanks dude, I see I just needed a . there...

Simpler than my version. Simple=good but bear in mind that using .* will strip everything up to the last } in the line as the * operator is by default 'greedy' and matches as much as it can. That's fine for subtitles, I don't expect many of them contain closing curly braces.
 
Last edited by a moderator:
Here is the pattern that I think you wanted.

The pattern ":%s/>.*}//" would replace the following by a blank line.
> junk }

From the pattern that you mentioned it appears as though you are trying to replace the line with a ">", so you could do that with ":%s/>.*}/>/"

I will explain the different parts of the command for those who are not familiar with vi/vim.

":%s" is a search and replace command for an entire file.

"/>.*}/" specifies the search pattern in between "/" and the ".*" says to match any character zero or more times.

"/>/" is the replace string (or "//" for an empty string).

--Jeff
 
damn, i had no idea vi was so flexible. i'm gonna have to spend some more time with it...all i really use with it now is "x", "i", and "ZZ"...
 
Back
Top