use sed do batch wildcard string replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use sed do batch wildcard string replace
# 1  
Old 07-06-2009
use sed do batch wildcard string replace

Hi,
Here is what I want to do
I want to search local directory and its sub directory, all the files which contain any string like _12345, then remove this string.
String is a combination of _ plus a random integer number.
For example, here is one line in a file before
<properties xmi:id="Property_1246046473688" name="com.ibm.websphere.wxdcgProductVersion" value="6.1.0.4"/>
after change, it should become
<properties xmi:id="Property" name="com.ibm.websphere.wxdcgProductVersion" value="6.1.0.4"/>

Please help.
# 2  
Old 07-06-2009
Code:
function replace
{
	dir=$1
	for i in `ls $dir`;do
		file=$dir/$i
		if [ -f $file ];then
			sed 's/\(Property_\)[0-9][0-9]*/\1/g' $file > $file.bak
		else
			replace ${dir}/${i}
		fi
	done
}
path=`pwd`
for i in *;do
if [ -f $i ];then
	egrep 'Property_[0-9]+' $i
	if [ $? -eq 0 ];then 
		sed 's/\(Property_\)[0-9][0-9]*/\1/g' $i > $i.bak
	fi
else
	replace ${path}/${i}
fi
done

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

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

3. Shell Programming and Scripting

sed replace characters using a wildcard

Hello, I have some data that looks like the following, > <SALTDATA> (OVS0199262) HCl > <IDNUMBER> (OVS0199262) OVS0199262 > <SUPPLIER> (OVS0199262) TimTec > <EMAIL> (OVS0199262) info@timtec.net > <WEBSITE> (OVS0199262) http://www.timtec.net I need to remove the data in... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

Sed or awk for batch replace file name

Can you please point me in the correct direction? I need a line or script to run though a given directory and find all files with "@domain.local" in there names and simple remove that. For example if the files were named 1234@domain.local the file would then become 1234. (1 Reply)
Discussion started by: binary-ninja
1 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

sed delete wildcard within a string

Hi I would like to batch delete the "note" entry from bib files. The start would be defined by "note ={" and the end by "}." (see example bib entry below). I tried the following command which does not have any effect: cat input.bib| sed -e 's/note = {.*}.//' > output.bib Any help would... (2 Replies)
Discussion started by: gerggeismann
2 Replies

8. Shell Programming and Scripting

Find replace a particular string of data with wildcard

Hi I am having a csv file in which lots of data are available wherein i need to find a particular kind of data and replace it with null value. here is the sample data.. I need to find the string starting with 404-064- and up to the first space i have to remove the data and keep the... (4 Replies)
Discussion started by: aemunathan
4 Replies

9. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

10. Shell Programming and Scripting

how to cut string with wildcard (sed)

i got text file and contain.... SKYPE Dec 11 09:26:05 IN=eth0 OUT=eth1 SRC=75.38.161.80 DST=192.168.1.56 PROTO=UDP SPT=30645 DPT=12630 LEN=66 SKYPE Dec 11 09:26:05 IN=eth1 OUT=eth0 SRC=192.168.1.56 DST=118.109.39.86 PROTO=UDP SPT=12630 DPT=15889 LEN=75 SKYPE Dec 11 09:26:05 IN=eth1 OUT=eth0... (2 Replies)
Discussion started by: slackman
2 Replies
Login or Register to Ask a Question