Reputation: 669
I have a text file with entries like below
LondonTableABC
ROW1
Cell1
Row2
ParisTableBCD
ROW1
ROW2
NewYorkTableEFG
ROW1
ROW2
I want to insert a line break before the matching pattern "Table" in the file. Find and replace has been my friend for a task like this to insert a new line AFTER the matching pattern but I can't figure out how to insert it BEFORE the matching pattern.
The result I expect after the replacement is
LondonTableABC
ROW1
Cell1
Row2
ParisTableBCD
ROW1
ROW2
NewYorkTableEFG
ROW1
ROW2
Upvotes: 4
Views: 11730
Reputation: 91415
Not sure to well understand your needs, but I guess you want:
^.+Table
\n$0
Explanation:
^ : begining of line
.+ : 1 or more any character
Table : literally Table
Replacement:
\n : line break (you could use \r\n if requested)
$0 : whole match (ie. Table)
Result for given example:
LondonTableABC
ROW1
Cell1
Row2
ParisTableBCD
ROW1
ROW2
NewYorkTableEFG
ROW1
ROW2
Upvotes: 8
Reputation: 17839
Open Find Replace (CTRL+H)
Select "Extended" in search mode
Find what: Pattern
Replace With: \nPattern
Replace All
Upvotes: 4