Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » add a word to the beginning of each line of the source file
add a word to the beginning of each line of the source file [message #658429] Tue, 08 March 2011 13:45 Go to next message
albertkao is currently offline albertkaoFriend
Messages: 46
Registered: February 2010
Member
How to add a word to the beginning of each line of the source file with the default editor for Java?

I know how to do that with the vi editor:
change to command mode.
for the current line:
s/^/my word/

for lines 10 to 30:
10,30s/^/my word/

[Updated on: Tue, 08 March 2011 13:46]

Report message to a moderator

Re: add a word to the beginning of each line of the source file [message #658466 is a reply to message #658429] Tue, 08 March 2011 15:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020003070903000702010201
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

You could install this editor

http://www.viplugin.com/viplugin/

It's well worth the nominal cost to have all the power of vi at your
finger tips in every text editor.


albertkao wrote:
> How to add a word to the beginning of each line of the source file
> with the default editor for Java?
>
> I know how to do that with the vi editor:
> change to command mode.
> s/^/my word/

--------------020003070903000702010201
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
You could install this editor<br>
<blockquote><a href="http://www.viplugin.com/viplugin/">http://www.viplugin.com/viplugin/</a><br>
</blockquote>
It's well worth the nominal cost to have all the power of vi at your
finger tips in every text editor.<br>
<br>
<br>
albertkao wrote:
<blockquote cite="mid:il5bg7$nh2$1@news.eclipse.org" type="cite">How to
add a word to the beginning of each line of the source file with the
default editor for Java?
<br>
<br>
I know how to do that with the vi editor:
<br>
change to command mode.
<br>
s/^/my word/
<br>
</blockquote>
</body>
</html>

--------------020003070903000702010201--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: add a word to the beginning of each line of the source file [message #658467 is a reply to message #658429] Tue, 08 March 2011 15:43 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 3/8/2011 7:15 PM, albertkao wrote:
> How to add a word to the beginning of each line of the source file with
> the default editor for Java?
>
> I know how to do that with the vi editor:
> change to command mode.
> s/^/my word/

- Ctrl+H to open Search dialog
- Navigate to File search tab
- Check regular expressions option
- Enter search pattern as "\n"
- Set scope appropriately
- Click 'Replace'
- Enter replace pattern as "\nword"

This will add the word to the beginning of each line except the first line.
Re: add a word to the beginning of each line of the source file [message #658587 is a reply to message #658467] Wed, 09 March 2011 07:12 Go to previous messageGo to next message
Lorenz is currently offline LorenzFriend
Messages: 11
Registered: July 2009
Junior Member
Deepak Azad wrote:

>On 3/8/2011 7:15 PM, albertkao wrote:
>> How to add a word to the beginning of each line of the source file with
>> the default editor for Java?
>>
>> I know how to do that with the vi editor:
>> change to command mode.
>> s/^/my word/
>
>- Ctrl+H to open Search dialog
>- Navigate to File search tab
>- Check regular expressions option
>- Enter search pattern as "\n"
>- Set scope appropriately
>- Click 'Replace'
>- Enter replace pattern as "\nword"
>
>This will add the word to the beginning of each line except the first line.

replacing "^(.*)" with "word\1" works for the first line too
--

Lorenz
Re: add a word to the beginning of each line of the source file [message #658751 is a reply to message #658587] Wed, 09 March 2011 16:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010405020207070909000400
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

That's better because it works regardless of the line feed conventions
of the resource (which could be \n, \r, or \n\r)....

Lorenz wrote:
> Deepak Azad wrote:
>
>
>> On 3/8/2011 7:15 PM, albertkao wrote:
>>
>>> How to add a word to the beginning of each line of the source file with
>>> the default editor for Java?
>>>
>>> I know how to do that with the vi editor:
>>> change to command mode.
>>> s/^/my word/
>>>
>> - Ctrl+H to open Search dialog
>> - Navigate to File search tab
>> - Check regular expressions option
>> - Enter search pattern as "\n"
>> - Set scope appropriately
>> - Click 'Replace'
>> - Enter replace pattern as "\nword"
>>
>> This will add the word to the beginning of each line except the first line.
>>
>
> replacing "^(.*)" with "word\1" works for the first line too
>

--------------010405020207070909000400
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
That's better because it works regardless of the line feed conventions
of the resource (which could be \n, \r, or \n\r)....<br>
<br>
Lorenz wrote:
<blockquote cite="mid:80aen694dpoa883nhuq4m7actmu0mdm62e@4ax.com"
type="cite">
<pre wrap="">Deepak Azad wrote:

</pre>
<blockquote type="cite">
<pre wrap="">On 3/8/2011 7:15 PM, albertkao wrote:
</pre>
<blockquote type="cite">
<pre wrap="">How to add a word to the beginning of each line of the source file with
the default editor for Java?

I know how to do that with the vi editor:
change to command mode.
s/^/my word/
</pre>
</blockquote>
<pre wrap="">- Ctrl+H to open Search dialog
- Navigate to File search tab
- Check regular expressions option
- Enter search pattern as "\n"
- Set scope appropriately
- Click 'Replace'
- Enter replace pattern as "\nword"

This will add the word to the beginning of each line except the first line.
</pre>
</blockquote>
<pre wrap=""><!---->
replacing "^(.*)" with "word\1" works for the first line too
</pre>
</blockquote>
</body>
</html>

--------------010405020207070909000400--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: add a word to the beginning of each line of the source file [message #659005 is a reply to message #658587] Thu, 10 March 2011 16:33 Go to previous messageGo to next message
albertkao is currently offline albertkaoFriend
Messages: 46
Registered: February 2010
Member
All the sentences become "word1".
Re: add a word to the beginning of each line of the source file [message #659012 is a reply to message #659005] Thu, 10 March 2011 16:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
You tried the same patterns you originally asked about? (\1 is the
capture from the left side match; maybe that's not supported)

albertkao wrote:
> All the sentences become "word1".


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Eclipse won't start (missing a file)
Next Topic:Navigator not displaying new project or SVN checkouts
Goto Forum:
  


Current Time: Thu Apr 25 13:10:29 GMT 2024

Powered by FUDForum. Page generated in 0.10735 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top