[nylug-talk] noob bash sed confusion
Yusuke Shinyama
Thu Nov 2 18:41:41 EST 2006
On Thu, 02 Nov 2006 18:33:42 -0500, jh <jhlists at hirschman.net> wrote:
> I'm trying to use sed in bash, and i'm getting rather confused with
> quotes and escapes. I'm hoping that someone can help...
>
> OK, this works fine from the bash prompt:
>
> sed -e 's/source\ src\ {/source\ src\
> {unix-stream("\/home\/foo2\/dev\/log");/g' file.txt
>
> I'd like to do the same thing, but use a variable for the replace
> argument instead of foo2. How can I do this within a bash script?
You can mix single and double-quoted strings within one argument:
$ i=2
$ echo '1'"$i"'3'
123
Also, you don't have to use always a / for the pattern delimiter.
So...
$ for i in a b c; do echo sed -e 's.source src {.source src {unix-stream("/home/'"$i"'/dev/log");.g' file.txt; done
sed -e s.source src {.source src {unix-stream("/home/a/dev/log");.g file.txt
sed -e s.source src {.source src {unix-stream("/home/b/dev/log");.g file.txt
sed -e s.source src {.source src {unix-stream("/home/c/dev/log");.g file.txt
Yusuke
More information about the nylug-talk
mailing list