The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-07-2008
ggggdddd ggggdddd is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
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?
  #2 (permalink)  
Old 09-07-2008
BMDan BMDan is offline
Registered User
  
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
Quote:
Originally Posted by ggggdddd View Post
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?
Not clear why there's a colon at the start; is this vim? Here's how to do it in vim:
Code:
:%s/Mg\([24]\).\(q[np]s[b]?\) W=0\.175u/Mg\1.\2 W=wmg\1\2/g
  #3 (permalink)  
Old 09-07-2008
ggggdddd ggggdddd is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
Quote:
Originally Posted by BMDan View Post
Not clear why there's a colon at the start; is this vim? Here's how to do it in vim:
Code:
:%s/Mg\([24]\).\(q[np]s[b]?\) W=0\.175u/Mg\1.\2 W=wmg\1\2/g
Thanks!
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
  #4 (permalink)  
Old 09-08-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Code:
sed 's/\(.*\)\.\(.*\) W=\(.*\)./\1.\2 W=w\1\2/' filename
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0