Find and replace string matching criteria


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and replace string matching criteria
# 1  
Old 07-11-2012
Find and replace string matching criteria

Dear Friends,
I am looking for a way to replace a string (multiple lines) starting with something and ending with something (these two values do not change) with blank. Basically I want to delete this code injection accross many sites and folders.
Code:
 
Search Code (across files and folders) that starts with /*km0ae9gr6m*/
(different variety of code in between)
and ends with /*qhk6sa6g1c*/
and replace it with blank

Thanks.
# 2  
Old 07-11-2012
Like this?
Code:
$ cat file
not to be deleted 1
not to be deleted 2
/*km0ae9gr6m*/
to be deleted
to be deleted
to be deleted
to be deleted
to be deleted
to be deleted
/*qhk6sa6g1c*/
not to be deleted 3
$ 
$ 
$ sed '/\/\*km0ae9gr6m\*\//,/\/\*qhk6sa6g1c\*\// d' file
not to be deleted 1
not to be deleted 2
not to be deleted 3
$

# 3  
Old 07-11-2012
Yes but the starting and ending words needs to be deleted too along with whatever is in the middle and it needs to search for this pattern across files and folders.

Thanks alot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace String matching wildcard pattern

Hi, I know how to replace a string with another in a file. But, i wish to replace the below string pattern EncryptedPassword="{gafgfa}]\asffafsf312a" i.e EncryptedPassword="<any random string>" To EncryptedPassword="" i.e remove the random password to a empty string. Can you... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Need a Linux command for find/replace column based on specific criteria.

I'm new to shell programming, I have a huge text file in the following format, where columns are separated by single space: ACA MEX 4O_ $98.00 $127.40 $166.60 0:00 0:00 0 ; ACA YUL TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ; ACA YYZ TS_ $300.00 $390.00 $510.00 0:00 0:00 0 ; ADZ YUL TS_ $300.00... (3 Replies)
Discussion started by: transat
3 Replies

3. Linux

Merge two files based on matching criteria

Hi, I am trying to merge two csv files based on matching criteria: File description is as below : Key_File : 000|ÇÞ|Key_HF|ÇÞ|Key_FName 001|ÇÞ|Key_11|ÇÞ|Sort_Key22|ÇÞ|Key_31 002|ÇÞ|Key_12|ÇÞ|Sort_Key23|ÇÞ|Key_32 003|ÇÞ|Key_13|ÇÞ|Sort_Key24|ÇÞ|Key_33 050|ÇÞ|Key_15|ÇÞ|Sort_Key25|ÇÞ|Key_34... (3 Replies)
Discussion started by: PK29
3 Replies

4. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

5. UNIX for Dummies Questions & Answers

How to fetch files right below based on some matching criteria?

I have a requirement where in i need to select records right below the search criteria qwertykeyboard white 10 20 30 30 40 50 60 70 80 qwertykeyboard black 40 50 60 70 90 100 qwertykeyboard and white are headers separated by a tab. when i execute my script..i would be searching... (4 Replies)
Discussion started by: vinnu10
4 Replies

6. Shell Programming and Scripting

Find the position of lines matching string

I have a file with the below format, GS*8***** ST*1******** A* B* E* RMR*123455(This is the unique number to locate this row) F* SE*1*** GE** GS*9***** ST*2 H* J* RMR*567889(This is the unique number to locate this row) L* SE* GE***** (16 Replies)
Discussion started by: Muthuraj K
16 Replies

7. Shell Programming and Scripting

Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format

Hi, I'm very new to shell scripting and have searched google and this forum for quite some time now. I have the following in my xml file: <recipients> <member>value1</member> </recipients> I need to find a string <recipients> that follows with a new-line and bunch of spaces and... (5 Replies)
Discussion started by: mgharios
5 Replies

8. Shell Programming and Scripting

Need to find a string, check the next line, and if it matches certain criteria, replace it with a s

Hey Fellas. I am new to scripting. I have searched through the forums and found a lot of good info, but I can't seem to get any of it to work together. I am trying to find a particular sting in a file, and if the next string matches certain criteria, replace it with a string from a csv... (6 Replies)
Discussion started by: midniteslice
6 Replies

9. Shell Programming and Scripting

making a list matching certain criteria in bash...

Hello everyone!I am trying to make a mail list(a simple .txt file)in which i put certain records that match specific criteria. Let's say that i have a(sorted by last column file)like this one: 0100567 Bla1 Lala1 100 1234567 Bla2 Lala2 80 8769029 Bla3 Lala3 70 1001007 ... (0 Replies)
Discussion started by: bashuser2
0 Replies

10. Shell Programming and Scripting

deleting files and folders matching criteria

Hello, I'm spendind hours trying to figure out how a script could remove files and folders older than 30days in a given volume (/dataVolumes/Booba.1.0). Within this volume, all users have their personal folder that starts with "RC-..", so the script should skip them for deletion. I will... (4 Replies)
Discussion started by: H3001
4 Replies
Login or Register to Ask a Question