bash : (find + grep + sed) to edit only some of matching occurrences
Hi!
In a <path> (directory) containing some <file>.txt them self containing lines like: Code:
<chain1><something else> Code:
find <path> -type f -name "*.txt" -exec sed -i 's/<chain1>/<chain2>/g' '{}' \; Code:
<chain1><something else> Code:
<chain2><something else> But what I really want, is only to change : Code:
<chain1><something else containing <chain3> > Code:
<chain2><something else containing <chain3> > Is there some way to insert a Code:
grep <chain3> Thanks for help! |
Quote:
I am lazy and assume that <chain1> always occurs before <chain3> in a line. Code:
sed '/<chain3>/s/<chain1>/<chain2>/' OK, here is a more water-tight way to do it: Code:
sed '/<chain1>.*<chain3>/s/<chain1>/<chain2>/' |
maybe in a script due to if else clause. if you're doing simple name changing.
Code:
#!/bin/bash |
@berndbausch
Your first "lazy" proposal works perfectly :)) sed is a very usefull piece of code I thank you! @BW-userx Effectively I was wondering myself if this action require some logical/conditional statement to be achieved But I still don't know how to do that :(( I've tried a few around your example script, but that doesn't work. What I don't understand is why to use mv, my intention is to modify the files content not there names. I thank you too for the trail For me the subject is solved :)) |
Quote:
|
All times are GMT -5. The time now is 01:01 AM. |