Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a text file of a couple of hundred thousand words. E.g.:

word1
word2
etc

I want to know what program I can use to easily:

  1. Add "FRONT" to the front of the text, and
  2. Add "BACK" to the end of the text

So I would end up with:

FRONTword1BACK
FRONTword2BACK
FRONTetcBACK

I can easily do this by coding it in PHP, but I want to know if there is a faster way, with the correct tool? Perhaps this can be done in something like notepad++, or scite, or worst case scenario, linux command line.

Note: I would prefer a WINDOWS based visual editor.

share|improve this question
3  
Umm? Yes- Notepad++ - use regular expression replacment –  ppumkin Aug 17 '12 at 10:12
    
Okay, can you explain how? And I was hoping I could avoid regular expressions, because they are a pain. –  coderama Aug 17 '12 at 10:13
1  
NO! Regular expressions are the way to do it. Otherwise do it in PHP like you said. –  ppumkin Aug 17 '12 at 10:15
1  
sourceforge.net/apps/mediawiki/notepad-plus/… The examples might help! –  user905686 Aug 17 '12 at 10:23
add comment

2 Answers 2

VIM works on Windows. If you never used it you may have problems starting, but if you learn the basics all the magic is available.

1) Add something in front of first character in every line:

  • Go to first line, first column.
  • Ctrl+v Ctrl+q to enter visual block mode.
  • Ctrl+g to go to last line.
  • Shift+i to enter visual inserting mode.
  • Enter the text and press Esc. Text should appear in all lines.

2) Add something at the end. If all words have same length you can do as described above. If not use macros.

  • Go to first line.
  • Press 'q' twice. First starts recording, second chooses a buffer to record to (can be any letter).
  • Shift+a to start inserting text at the end of the line.
  • Type desired text.
  • Esc to stop inserting.
  • Down arrow or 'j' to go to next line.
  • 'q' again to stop recording.
  • Now you can replay recorded action typing '@@' or '@q'. '@@' replays last record, '@q' replays the one under 'q' buffer (same thing in this example).
  • Type '1000@@' to replay macro 1000 times.
share|improve this answer
    
Thanks, but CTRL-V with windows VIM does a "paste". I will keep trying... –  coderama Aug 17 '12 at 10:54
    
Try ctrl+q, should not conflict with Windows pasting. –  zergu Aug 17 '12 at 12:24
add comment

In NotePad++ do a regular expression replace:

Find what: ^(.*)$

Replace with: FRONT\1BACK

What's going on in regex terms?

^ - matches start of line
$ - matches end of line
.* - matches everything in between (in brackets to mark it as a group)

The replace is simply what you want to pre and post fix and the value of the first regex group (ie everything on the line) sandwiched in the middle.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.