The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with finding & replacing pattern in a file dusoo Shell Programming and Scripting 0 05-23-2008 12:59 AM
Replacing more than 1 pattern in a line Manan Shell Programming and Scripting 6 12-27-2006 10:58 PM
Replacing a paragraph between pattern , with the content 4m another file go4desperado Shell Programming and Scripting 4 12-07-2006 06:44 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 12:41 PM
Replacing pattern in variable videsh77 Shell Programming and Scripting 1 05-26-2005 11:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-10-2008
Registered User
 

Join Date: Mar 2008
Posts: 48
replacing a pattern in a file

Hi guys,
i have a pattern that i am searching in a file and i want to extract some of this pattern

...
module TS1N65ULPA96X32M4 (
....

i want to extract only TS1N65ULPA96X32M4 part and i do the following

sed 's/module \([a-z0-9]x[a-z0-9]*\).*/\1/' name_of_file

but this is not quite right.
could someone help me to do the above.
Reply With Quote
Forum Sponsor
  #2  
Old 06-10-2008
Registered User
 

Join Date: Mar 2008
Posts: 48
i forgot to ask another question related to this one,
how could i replaced the number 96 and 32 within TS1N65ULPA96X32M4
with some variables that i have.
i was wondering if i could use something like
sed 's/ TS1N65ULPA96X32M4/ TS1N65ULPA$VARIABLE1X$VARIABLE2M4/'
but this obviously does not work
could someone help me with this one too. i posted the two questions here because they are relevant to each other
Reply With Quote
  #3  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Quote:
Originally Posted by ROOZ View Post
i was wondering if i could use something like
sed 's/ TS1N65ULPA96X32M4/ TS1N65ULPA$VARIABLE1X$VARIABLE2M4/'
but this obviously does not work
It doesn't work because you need double quotes and curly braces around variable names:
Code:
sed "s/ TS1N65ULPA96X32M4/ TS1N65ULPA${VARIABLE1}X${VARIABLE2}M4/" input_file.txt
Reply With Quote
  #4  
Old 06-10-2008
Registered User
 

Join Date: Mar 2008
Posts: 48
Quote:
Originally Posted by robotronic View Post
It doesn't work because you need double quotes and curly braces around variable names:
Code:
sed "s/ TS1N65ULPA96X32M4/ TS1N65ULPA${VARIABLE1}X${VARIABLE2}M4/" input_file.txt
Thanks it was very helpful
i hope i will get an answer for the first question too
Reply With Quote
  #5  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
I didn't understand very well your first problem or, at least, what's its relation with the second

Anyway, with sed:
Code:
sed "/module/s/^.* \(.*\) .*$/\1/" input_file.txt
With awk:
Code:
awk '/module/ { print $2 }' input_file.txt
Reply With Quote
  #6  
Old 06-10-2008
Registered User
 

Join Date: Mar 2008
Posts: 48
Quote:
Originally Posted by robotronic View Post
I didn't understand very well your first problem or, at least, what's its relation with the second

Anyway, with sed:
Code:
sed "/module/s/^.* \(.*\) .*$/\1/" input_file.txt
With awk:
Code:
awk '/module/ { print $2 }' input_file.txt
Thanks for your help it work just fine but i replaced " with ' .
Reply With Quote
  #7  
Old 06-11-2008
Registered User
 

Join Date: Mar 2008
Posts: 48
Quote:
Originally Posted by robotronic View Post
I didn't understand very well your first problem or, at least, what's its relation with the second

Anyway, with sed:
Code:
sed "/module/s/^.* \(.*\) .*$/\1/" input_file.txt
With awk:
Code:
awk '/module/ { print $2 }' input_file.txt

I think i was not clear with this question,so I am going to try to explain it again:
i have a file which contains a verilog code. this verilog code contain the following line at some point:
..........................
...................the begining of the code
.....
module TS1N65ULPA256X16M4 (
CLK, CEB, WEB,

A, D, BWEB,

Q,

TSEL
);
.......the rest of the code

i am interested in TS1N65ULPA256X16M4 which appears after module and before (.
i was wondering how to extract TS1N65ULPA256X16M4.
could someone please help me with this
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0