LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 08-17-2007, 09:22 AM   #1
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,159

Rep: Reputation: 202Reputation: 202Reputation: 202
Complicated VI replacement with variable expression


I have n lines of code (n big enough to make this reasonable)

all of which have this format:

ABcD, where A,B,D are constant string, and c is a variable string. for example...

Code:
...
ham tuna donkey potato
ham tuna horse potato
ham tuna giraffe potato
...

I am trying to come up wtih a VI replacement command to change my
ABcD pattern to Ac'cD, where c' is the string c, but with # in front of it.

So I would have:

Code:
...
ham #donkey donkey potato
ham #horse horse potato
ham #giraffe giraffe potato
....
any ideas?

Thank you!
Jameson

Last edited by jhwilliams; 08-17-2007 at 09:27 AM.
 
Old 08-17-2007, 09:44 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,514
Blog Entries: 1

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Hi,

Try this:

:%s/\([a-z]*\) \([a-z]*\) \([a-z]*\) \([a-z]*\)/\1 #\3 \3 \4/

If you also need uppercase and/or numbers you need to adjust the [a-z] parts accordingly.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace variable with user defined variable ce124 Programming 10 04-13-2007 09:29 AM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM
Scripting: accessing a variable stored in a variable? tomolesonjr Linux - Newbie 5 05-05-2006 08:47 PM
ipw2200 ...this looks complicated jnsg Slackware 7 12-22-2005 11:03 AM
why must linux be so complicated? r_hartless Linux - Newbie 7 07-12-2004 01:50 AM


All times are GMT -5. The time now is 06:25 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration