![]() |
Looking for a "add characters" script
I'm working with text edit and Word for Mac.
I have a list with 110 lines and I want to add at the beginning of each line the same characters ( in my case <track><location>..)and some other characters at the end. Is there an existing script that can do that for me automatically? Thank you |
What's wrong with using find/replace?
In word: find: ^p replace: other_characters^p<track><location> |
I'd recommend getting "TextWrangler" (free) and using that instead of TextEdit. TextWrangler has various ways to do what you want - e.g via the Search/Replace dialog.
|
Yes, TextWrangler is much better. In it, you'd do:
find: \r replace: other_characters\r<track><option> |
Quote:
^p is for after the phrase; which is for the beginning of the phase? Do you know how do I duplicate each single line, one after the other? Example: title1 title2 should become: title1 title1 title2 title2 Thank you. |
in vi you can do this using the 'I' command (insert at beginning of line)
and the 'A' command (append at end of line) Also, vi provides for what's called visual block editing ('Ctrl-V') where you select a block then using 'I'/'A' you can insert/append to that internal block or use 'd' to delete the block you've selected I used it extensively when editing some xml and xsl files. Dale |
Sorry, what means vi?
|
Quote:
you can use: ^(.*)$ replaced with: \1\r\1 but some editors prefer: $1\r$1 in vi you can use: %s/^\(.*\)$/\1\r\1/g (you must input backslash '\' before parenthesis for vi to understand you want to group) Dale |
Quote:
(the terminal is found in /Applications/Utilities -> Terminal.app) However it is a very powerful editor which needs a lot of time to learn, because it doesn't have a graphical interface like TextEdit If you are interested in using it, there is MacVim which a bit of a graphical interface which can help you at the beginning to learn how to use vi (or vim which is an extension of vi) MacVim: http://code.google.com/p/macvim/ |
Quote:
I went through the tutorial but I did not found the following: a)find and replace at the beginning of lines b)\r is for find and replace at the end of lines c) how to duplicate each single line following this example: line1 line2 should become: line1 line1 line2 line2 Thanks for your help |
In Word, (and I assume Textwrangler) ^p (sometimes /p) just means "paragraph break". So you can use that at the start or the end of a line.
Example: Search for line1^p replace with line1^pline1^p Search for line2^p replace with line2^pline2^p |
Sorry, I was wrong
Quote:
|
OK, I got it.
beginning of line: find:\r, replace:\r text end of line: find:\r, replace:text \r There is still my question about how to duplicate. Consider that I have 110 lines: line1 line2 ... should become: line1 line1 line2 line2 ... ... |
If you want every line in the file to be duplicated, you could do that using the 'paste' command (in a Terminal window).
For example, if the file is named "foo.txt": Code:
% cat foo.txt |
You could use this Applescript with TextWrangler:
Code:
tell application "TextWrangler" |
Perfect, your applescript works perfectly. Thank you very much.
|
Quote:
|
It was good, but regexp are intimidating, especially if you aren't used to coding at all. That's why I went with Applescript. It's the least intimidating option I know.
|
apple script rules, I would also say regexp rules but I have no idea what it is exactly.
|
Quote:
may I ask you some more help? Can you write another applescript? I have 220 lines with 110 titles. Here the example: title1 title1 title2 title2 .... This should become: <location>title1</location> <title>title1</title> <location>title2</location> <title>title2</title> ... I think we have two way to solve it: a)write an applescript b)use the find/replace function (but every second line must be replaced) Can you help me please? |
%s/^\(.*\)\n\1$/<location>\1<\/location>\r<title>\1<\/title>/g
|
Scary!
Code:
tell application "TextWrangler" |
Thank you very much
Great job, thank you. I wish I can write applescripts.
|
It's easy! Just do one step at a time until you're done. Here it is with comments:
Code:
tell application "TextWrangler" -- Tells Applescript that you want to instruct TextWrangler what to do |
| All times are GMT -5. The time now is 11:07 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.