![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| The Tough Software Business | iBot | Cartoons for Geeks | 0 | 07-25-2008 06:40 PM |
| Perl Arrays and Substituion | popeye | Shell Programming and Scripting | 1 | 05-06-2008 05:29 AM |
| Env Variable substituion in Sed (-s option) | gvsreddy_539 | Shell Programming and Scripting | 5 | 09-27-2007 04:00 PM |
| Tough makefile question | mbbeaubi | High Level Programming | 1 | 06-04-2007 05:15 PM |
| Seems the Shell Script is very tough | prince_of_focus | Shell Programming and Scripting | 1 | 07-18-2006 05:05 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Tough Substituion command
I have lines like:
Mg2.qns W=0.175u Mg2.qpsb W=0.175u Mg4.qns W=0.175u Mg4.qpsb W=0.175u Which I need to become: Mg2.qns W=wmg2qns Mg2.qpsb W=wmg2qpsb Mg4.qns W=wmg4qns Mg4.qpsb W=wmg4qpsb To acheive this individually line by line I use a command like: :g/Mg2\.qns/s/W=.*/W=wmg2qns/ However I wish to acheive this for all lines in one command I can find all the lines containing the concerned words by using: :g/Mg[24]\.q[np]s/s/?????????????????????? I do not know how to fill up the second part of the command represented by question marks. Any idea? |
|
||||
|
Quote:
Code:
:%s/Mg\([24]\).\(q[np]s[b]?\) W=0\.175u/Mg\1.\2 W=wmg\1\2/g |
|
||||
|
Quote:
I am using Vi. I tried using the command but it did not execute. (Even tried in vim) I tried searching for /Mg\([24]\).\(q[np][as]\) and it could find all the lines. But when I search for /Mg\([24]\).\(q[np][as][b]?\) It cannot find anything. How can I make the presence of that last charachter b optional in the substitution command? One more question: How do I substitute in case I have some charachters in between Mg...... and W=175u like below. These in between charachters should not be disturbed. Mg2.qns A B C L=123u W=0.175u Mg2.qpsb DE 12 c1 L=123u W=0.175u Mg4.qns M N O W=0.175u Mg4.qpsb W=0.175u Last edited by ggggdddd; 09-07-2008 at 11:06 PM.. Reason: More details added |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|