Re: How to replace two strings in a file in the same time with sed command ?
On Tue, Dec 11, 2007 at 10:21:22PM +0200, Halid Faith wrote: > Ok > But I have another problem, > I couldn't use any command interior of sed command. That's to say I have a > script; > > yy="file5" > for i in `cat file1`; > do > sed -e 's/old1/new1\ \'$i'/g' -e 's/old2/'cut -d, -f 1 ${yy}'/g' file2 > > file3 > done > > When I run the script, I get an error, due to using cut command > yy=file5 for i in `cat file1` ; do sed -e "s/old1/new1 $i/g" -e "s/old2/`cut -d, -f 1 ${yy}`/g" file2 > file3 done I changed the single-quotes to double-quotes so that they can have their variables interpreted. The problem with this loop is that, at each iteration, file3 will be overwritten. -- John D. "Trix" Farrar __\\|//__ Basement.NET [EMAIL PROTECTED] (` o-o ') http://www.basement.net/ ---ooO-(_)-Ooo-- pgpFHWwWMbsPX.pgp Description: PGP signature
Re: How to replace two strings in a file in the same time with sed command ?
I get an error; sed: illegal option -- d usage: sed script [-Ealn] [-i extension] [file ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...] here's my script for i in $(cat /usr/path/test1); do sed -e s#old1#new1\ cut -d, -f 1 ${i}# -e s#old2#cut -d, -f 3 ${i}# file1 > file2 done cat test1 boby, e, 656a, allen, e, 987c, ... - Original Message - From: "Tino Engel" <[EMAIL PROTECTED]> To: "Halid Faith" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, December 11, 2007 11:22 PM Subject: Re: How to replace two strings in a file in the same time with sed command ? > Halid Faith schrieb: > > Ok > > But I have another problem, > > I couldn't use any command interior of sed command. That's to say I have a > > script; > > > > yy="file5" > > for i in `cat file1`; > > do > > sed -e 's/old1/new1\ \'$i'/g' -e 's/old2/'cut -d, -f 1 ${yy}'/g' file2 > > > file3 > > done > > > > When I run the script, I get an error, due to using cut command > > > > > > > > > For using environment variables in sed, you have to use # instead of / > > VAR="TEXT" > > sed s#OLD#${VAR}#g file1 > > Will replace OLD by TEXT. Do not use quotations here... > Rg, Tino > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "[EMAIL PROTECTED]" > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: How to replace two strings in a file in the same time with sed command ?
On Tue, Dec 11, 2007 at 06:20:50PM +0200, Halid Faith wrote: > I want to replace two or more strings in a file in the same time with sed > command. > How do I that ? You can specify the "-e command" parameter multiple times on a line: $ sed -e 's/foo/fee/g' -e 's/bar/baz/e' filename.txt -- John D. "Trix" Farrar __\\|//__ Basement.NET [EMAIL PROTECTED] (` o-o ') http://www.basement.net/ ---ooO-(_)-Ooo-- pgp3JSVrhjpOA.pgp Description: PGP signature
Re: How to replace two strings in a file in the same time with sed command ?
On Tuesday 11 December 2007 17:20:50 Halid Faith wrote: > I want to replace two or more strings in a file in the same time with sed > command. How do I that ? > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "[EMAIL PROTECTED]" just use -e s/foo/bar/ as many times as needed. e.g. %cat afile foo1 foo3 foo2 foo7 %sed -e s/foo1/bar1/ -e s/foo2/bar2/ -e s/foo3/bar3/ -i .bak afile %cat afile.bak foo1 foo3 foo2 foo7 %cat afile bar1 bar3 bar2 foo7 Dan ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: How to replace two strings in a file in the same time with sed command ?
Halid Faith schrieb: Ok But I have another problem, I couldn't use any command interior of sed command. That's to say I have a script; yy="file5" for i in `cat file1`; do sed -e 's/old1/new1\ \'$i'/g' -e 's/old2/'cut -d, -f 1 ${yy}'/g' file2 > file3 done When I run the script, I get an error, due to using cut command For using environment variables in sed, you have to use # instead of / VAR="TEXT" sed s#OLD#${VAR}#g file1 Will replace OLD by TEXT. Do not use quotations here... Rg, Tino ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: How to replace two strings in a file in the same time with sed command ?
Ok But I have another problem, I couldn't use any command interior of sed command. That's to say I have a script; yy="file5" for i in `cat file1`; do sed -e 's/old1/new1\ \'$i'/g' -e 's/old2/'cut -d, -f 1 ${yy}'/g' file2 > file3 done When I run the script, I get an error, due to using cut command > Do you mean something like: > > sed -e 's/string1/replacement1/g' -e 's/string2/replacement2/g' > > or > > sed -f instructions.sed > > instructions.sed: > > s/string1/replacement1/g > s/string2/replacement2/g > > --Alex > > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: How to replace two strings in a file in the same time with sed command ?
Halid Faith wrote: I want to replace two or more strings in a file in the same time with sed command. How do I that ? Do you mean something like: sed -e 's/string1/replacement1/g' -e 's/string2/replacement2/g' or sed -f instructions.sed instructions.sed: s/string1/replacement1/g s/string2/replacement2/g --Alex ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: How to replace two strings in a file in the same time with sed command ?
On Tuesday 11 December 2007 17:20:50 Halid Faith wrote: > I want to replace two or more strings in a file in the same time with > sed command. How do I that ? [EMAIL PROTECTED] ~ % echo "foobar" | sed 's/foo/goo/;s/bar/baz/' goobaz -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments GnuPG public key: http://itsuki.fkraiem.org/gpgkey signature.asc Description: This is a digitally signed message part.