Reputation: 430
I need to mass replace a string in many sql files (preferably in shell). The string I need to replace looks like this (20120408, 20120409, 20120410)
but it can have any amount of whitespace inside (not in the numbers though). For example it can be
(20120408, 20120409 , 20120410 ) or
( 20120408 , 20120409 , 20120410)
I need to put some other string, let's say (XXX) instead of it. The brackets must stay.
Thanks in advance for your help.
EDIT.
Let me be more specific. I need only strings of the types above converted to (xxx). This means that the numbers are important. I do NOT want just anything between two brackets to be replaced, so if I have (19002344) I don't want it replaced.
The only thing that needs to be replaced is the three numbers above in brackets with any amount of whitespace in between.
Hope this clear the misunderstanding.
Upvotes: 0
Views: 153
Reputation: 45662
Howabout this?
sed -e 's/20120408/XXX/' -e 's/20120409/YYY/' -e 's/20120410/ZZZ/' input
output:
(XXX, YYY , ZZZ ) or
( XXX , YYY , ZZZ)
or everything in one-go:
$ sed 's/20120408\|20120409\|20120410/XXX/g' input
(XXX, XXX , XXX ) or
( XXX , XXX , XXX)
update
$ cat input
( 20120408, 20120409 , 20120410 )
( 20120408, 20120409 , 19002344 )
$ sed 's/^(\s*20120408\s*,\s*20120409\s*,\s*20120410\s*)$/(xxx)/' input
(xxx)
( 20120408, 20120409 , 19002344 )
The above assumes one entry per line; if there are several use this instead:
sed 's/(\s*20120408\s*,\s*20120409\s*,\s*20120410\s*)/(xxx)/g' input
Upvotes: 1