ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Finished Programs

SOLVED: Insert text string to front / end of each line in a text file

(1/4) > >>

Hello all.

I have a request for a small program or script to insert text to the front and end of each line within a next .txt file. Or any ideas if there's a program already for this, I'm not having any lucky finding one.

Say I have a bunch of lines of text eg...

Then I want to append text to either side of each line of text. So I want "BEFORE" to go in front, and "AFTER" at the end. Eg

Here's an example of how I want to use it with image tags:
So each line has a new URL (but they don't always start the http://), something like this:

Gets tags on either side like this:
<img src="http.://img.01.jpg">
<img src="http.://img.02.jpg">

I would think that any decent text editor that allowed RegEx search/replace could handle that.

eg. Notepad2-Mod

^(.+)$ - Search for and put everything between the start, (^), and end, ($), of a line into a group.
<img src="\1"> - Replace with <img src=", followed by the original contents of the line \1, followed by ">.

Seemed to work fine here.

+1 for 4wd there.

That is the fastest and easiest way to do it. Nothing else will be significantly easier. (Also, regex is uber-cool and will give you god-like power. And all the cool kids are using it. You do want to be cool, right? -- Sorry -- I get all freaky weird around regex. They just drive me wild 'cause they're so awesome!) ;D

Just a note that my Clipboard Help+Spell is very well suited for performing operations like this on blocks of text that you select in any program.

If you have a bunch of text files to perform this on, then look elsewhere, but if you occasionally need to perform similar operations on a block of text, you can use CHS and even set up formatting presets to allow you to trigger it with a hotkey:

Thanks all.

Thanks for the REGEXP code 4wd. I will play around with it. I was going to see if I could combine it into a .vbs. Think it might be easier if I save all uploaded links sorted to different files already and I can just run on selected files in my file manager. Did find another method of doing this with vbs, but has to find specific phrase (http) which could change and not just new line..

Mouser, your program looks really good, I think it might do what I need once I get it set up and has a hotkey to automate it. Still need to look at how all the options work and what they do. Will look at it better when when I'm less blurry eyed.  

One thing I am wondering, I wanted to complicate it a bit more, I want to do something different for each second line! Can either of these ways skip lines or do something different on each line, please tell me if either can?  

eg I have 2 links for each picture- 1st is large, second is small version. And I want this to happen.


<a href="HTTP.://IMG.1.LARGE.jpg" target="_blank">
<img src="HTTP.://IMG.1.SMALL.jpg"/></a>
<a href="HTTP.://IMG.2.LARGE.jpg" target="_blank">
<img src="HTTP.://IMG.2.SMALL.jpg"/></a>

Then I can just join each second line with the line before it. I found a vbs script to that.


[0] Message Index

[#] Next page

Go to full version