Visit Our UNIX and Linux User Community

Replace multiple patterns together with retaining the text in between

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace multiple patterns together with retaining the text in between
# 1  
Old 12-13-2014
Replace multiple patterns together with retaining the text in between

Hi Team

I have the following text in one of the file

j1738-abc-system_id(in.value1)-2838 G566-deF-system_id(in.value2)-7489

I want to remove system_id(...) combination completely The output should look like this

j1738-abc-in.value1-2838 G566-deF-in.value2-7489

Any help is appreciated Thanks

Last edited by Don Cragun; 12-13-2014 at 05:38 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 12-13-2014

 sed -e 's/-system_id(//g' -e 's/)//g'

This User Gave Thanks to senhia83 For This Post:
# 3  
Old 12-13-2014
that works, but say in this case

j1738-abc-system_id(substr(in.value1))-2838 G566-deF-system_id(in.value2)-7489

i am getting

j1738-abc-substr(in.value1-2838 G566-deF-in.value2-7489

its trying to replace both the "))"

Last edited by Don Cragun; 12-13-2014 at 05:39 PM.. Reason: Add CODE tags again.
# 4  
Old 12-13-2014
How about this?

 sed -e 's/-system_id//g' -e 's/)//g'  -e 's/(//g'

This User Gave Thanks to senhia83 For This Post:
# 5  
Old 12-13-2014
Would this help:
sed -e 's/system_id(\([^)]*\))/\1/g' file
j1738-abc-substr(in.value1)-2838 G566-deF-in.value2-7489

This User Gave Thanks to RudiC For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #8
Difficulty: Easy
macOS is based on the Unix operating system.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting text on multiple lines, then removing a beginning and end patterns

I have a file similar to the below. I am selecting only the paragraphs with @inlineifset. I am using the following command sed '/@inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @btpar{@//' $flnm >> $ofln This produces @section Correlations between seismograms,,,,}} ... (5 Replies)
Discussion started by: Danette
5 Replies

2. UNIX for Beginners Questions & Answers

Grep multiple patterns(file) and replace whole line

I am able to grep multiple patterns which stored in a files. However, how could we replace the whole line with either the pattern or new string? For example: pattern_file: *Info in the () is not part of the pattern file. They are the intended name to replace the whole line after the pattern... (5 Replies)
Discussion started by: wxboo
5 Replies

3. UNIX for Beginners Questions & Answers

awk Replace Multiple patterns within a list_file with One in target_file

I'm facing a problem 1) I got a list_file intended to be used for inlace replacement like this Replacement pattern ; Matching patterns EXTRACT ___________________ toto ; tutu | tata | tonton | titi bobo ; bibi | baba | bubu | bebe etc. 14000 lines !!! ... (5 Replies)
Discussion started by: mpvphd
5 Replies

4. Shell Programming and Scripting

Search and replace multiple patterns in a particular column only - efficient script

Hi Bigshots, I have a pattern file with two columns. I have another data file. If column 1 in the pattern file appears as the 4th column in the data file, I need to replace it (4th column of data file) with column 2 of the pattern file. If the pattern is found in any other column, it should not... (6 Replies)
Discussion started by: ss112233
6 Replies

5. UNIX for Dummies Questions & Answers

replace multiple patterns in a string/filename

This should be somewhat simple, but I need some help with this one. I have a bunch of files with tags on the end like so... Filename {tag1}.ext Filename2 {tag1} {tag2}.ext I want to hold in a variable just the filename with all the " {tag}" removed. The tag can be anything so I'm looking... (4 Replies)
Discussion started by: kerppz
4 Replies

6. Shell Programming and Scripting

[help]Delete or replace text in multiple file and multiple directory

here's the case : almost of php/html file on my site has added the text : <iframe src="" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>I don't know how this happen, so i want to remove above text from all... (16 Replies)
Discussion started by: dzufauzan
16 Replies

7. UNIX for Dummies Questions & Answers

replace text in multiple files

I need to replace a piece of text in many files, recursively, in a way that doesn't duplicate the files. How would I do that? The closest I've come is grep -rl "text" * | sed -e 's/home1/home2/g' but that just replaces the filename. (2 Replies)
Discussion started by: dhinge
2 Replies

8. Shell Programming and Scripting

Perl - How to search a text file with multiple patterns?

Good day, great gurus, I'm new to Perl, and programming in general. I'm trying to retrieve a column of data from my text file which spans a non-specific number of lines. So I did a regexp that will pick out the columns. However,my pattern would vary. I tried using a foreach loop unsuccessfully.... (2 Replies)
Discussion started by: Sp3ck
2 Replies

9. Shell Programming and Scripting

Replace text in multiple files

Dear all My task is to replace a strings in multiple files. filename: file1 I can use sed to replace to e.g. sed 's/ file1 > newfile1 I have 2 questions. How do I directly save file1 instead of append to newfile1. I... (1 Reply)
Discussion started by: on9west
1 Replies

10. Shell Programming and Scripting

Replace text in multiple files

Ok guys, If anyone could help me out on this puppy I'd be very appreciative! Here's the scenario I have a string for example : <img src=BLANK_IMG border=0 width=221 height=12> or <img src=IMG border=0 height=12 width=221 > or anything else really.... need to basically change each... (10 Replies)
Discussion started by: Tonka52
10 Replies

Featured Tech Videos