replacing a pattern in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing a pattern in a file
# 1  
Old 06-10-2008
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.
# 2  
Old 06-10-2008
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
# 3  
Old 06-10-2008
Quote:
Originally Posted by ROOZ
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

# 4  
Old 06-10-2008
Quote:
Originally Posted by robotronic
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
# 5  
Old 06-10-2008
I didn't understand very well your first problem or, at least, what's its relation with the second Smilie

Anyway, with sed:
Code:
sed "/module/s/^.* \(.*\) .*$/\1/" input_file.txt

With awk:
Code:
awk '/module/ { print $2 }' input_file.txt

# 6  
Old 06-10-2008
Quote:
Originally Posted by robotronic
I didn't understand very well your first problem or, at least, what's its relation with the second Smilie

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 ' .
# 7  
Old 06-11-2008
Quote:
Originally Posted by robotronic
I didn't understand very well your first problem or, at least, what's its relation with the second Smilie

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern replacing

Hi, I have a text file with lots of text (strings,numbers,special characters etc). I am trying to replace any occurrence of these strings : 90% 91% 92% .... 100% I want to replace them with : "90%" "91%" "92%" .... "100%" I am now using 10 sed commands for replacement but I... (12 Replies)
Discussion started by: ctrld
12 Replies

2. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

3. Shell Programming and Scripting

Replacing a pattern in different cases in different columns with a single pattern

Hi All I am having pipe seperated inputs like Adam|PeteR|Josh|PEter Nick|Rave|Simon|Paul Steve|smith|PETER|Josh Andrew|Daniel|StAlin|peter Rick|PETer|ADam|RAVE i want to repleace all the occurrence of peter (in any case pattern PeteR,PEter,PETER,peter,PETer) with Peter so that output... (5 Replies)
Discussion started by: sudeep.id
5 Replies

4. Shell Programming and Scripting

replacing pattern

hi, I want to do replacing of some pattern by using sed. pattern : " white space / to white space / please help -bhrat (3 Replies)
Discussion started by: bhrat kapoor
3 Replies

5. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

6. Shell Programming and Scripting

Replacing pattern

Hi, I have a file which contains the below data. I want to search for a pattern server="http://bushby.mis.amat.com:12440" and remove it from the file. Please let me know how can i do this. <Object name="reverse-proxy-/endeavour/"> ObjectType fn="http-client-config" timeout="1800"... (6 Replies)
Discussion started by: Krrishv
6 Replies

7. Shell Programming and Scripting

Create a file after replacing a particular pattern in another file

I have a file as below: file1 ----- 1|CT1909090TRYGH 2|CTH909090GHDGJ 4|CT9909090HSGUS 10|AT0735732YQGDJ 21|CTP909090BAFSL 100|BAI891253NSHDD Now, I have to replace "909090" to "451234". Since after the pipe delimiter, the field positions are fixed, so i tried the below command: awk... (5 Replies)
Discussion started by: PriyankaM
5 Replies

8. Shell Programming and Scripting

Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello, The following sed command is giving error sed: -e expression #1, char 13: unknown option to `s' The sed command is echo "//-----" | sed "s/\/\/---*/$parChk/g" where parChk="//---ee-" How can i print the variable value from sed command ? And is it possible to replace a... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

help with finding & replacing pattern in a file

Hi everyone. Could u be so kind and help me with on "simple" shell script? 1. i need to search a file line by line for a pattern. example of a lines in that file 2947 domain = feD,id = 00 0A 02 48 17 1E 1D 39 DE 00 0E 00,Name Values:snNo = f10 Add AttFlag = 0 2. i need to find... (0 Replies)
Discussion started by: dusoo
0 Replies

10. Shell Programming and Scripting

Replacing a paragraph between pattern , with the content 4m another file

hi, i wanted to put the output of file f1 into the pattern space of file f2 f1: wjwjwjwjwjwjwj //these line go in file f2 jwjwjwjwjwjjwjw wjwjwjwjjwjwjwj f2: Pattern_start __________ //these are the line to be replaced __________ Pattern_end i m... (4 Replies)
Discussion started by: go4desperado
4 Replies
Login or Register to Ask a Question