tags:

views:

45

answers:

2

I have a huge file that has some lines that need to have a line of dashes underneath them followed by an empty line.

All of these lines start with the same particular word pattern ("Dollars required for") but every other word on the line is different from one line to the next.

For example, the document looks like this at the moment:

Dollars required for: "International Exchange"
Some other text on the next line
...
Dollars required for: "Trade Operations"
(blank line)
Some other text on the next line

But it needs to look like this:

Dollars required for: "International Exchange"
---------------------------------------------- (inserted line of dashes)
                                               (inserted blank line)
Some other text on the next line
...
Dollars required for: "Trade Operations"
---------------------------------------------- (inserted line of dashes)
                                               (inserted blank line)
(blank line)
Some other text on the next line

Is there a Regular Expression I could use in the Find/Replace feature of my text editor (Jedit) to perform this modification?

+1  A: 

Find:

Dollars required for: (.*)$

Replace with:

Dollars required for: $1\n----------------------------------------------\n

(This is assuming the find/replace supports escapes for newlines, et cetera.)

Amber
Cool! Thanks! Would that only target lines that *begin* with "Dollars required for" (in other words, the letter 'D' of the word 'Dollar' is the very first character on the line)?
Bowe
If you need to ensure that it's only lines which begin with that, add a `^` to the beginning of the match (`^` is the "start of line" anchor).
Amber
+1  A: 

Search for:

 ^(Dollars required for: .*)$

Replace with:

 $1\n----------------------------------------------\n\n

Jedit can do it IRC.

Zsolt Botykai
Having `\n\n` on the end would insert two blank lines, not one.
Amber
According to the question, that's the desired output.
Zsolt Botykai
No - there's already an existing blank line in the spot where the desired output shows two. You shouldn't be *adding* two, only one (for a sum total of twp).
Amber
I'm sorry if I'm misinterpreting but his desired output shows as: $1 -> line of dashes -> inserted blank line -> (Some other text on the next line) - at least in the first "section". And if I add only one then JEdit should not add the inserted blank line after the dash only line. Or am I wrong?
Zsolt Botykai