Re: sed substitution that contains forward slash
Craig White wrote: On Tue, 2009-03-31 at 20:16 -0400, Todd Zullinger wrote: Craig White wrote: subtitle...fun with sed I have a list of changes to make to a file... dc rc - --- 15T6145VDELETED NATL19502 DELETED Q10MR11/FL12V DELETED Q1500T3/CL120 DELETED and things work until I get to the 3rd item which has a forward slash and it fails to substitute with commands like below... sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv and sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv The latter producing error on screen... sed: -e expression #1, char 17: unknown option to `s' While the former simply doesn't complain but doesn't make the change either. Hmm, it should work using a delimeter other than '/' or escaping the '/'. Escaping the '/' is a bit more of a pain than just changing delimeters, as long as you know that whatever delimeter you pick won't be in the strings you are substituting. It seems to work for me: $ dc="Q10MR11/FL12V"; rc=DELETED; echo "dc=${dc}"; echo "rc=${rc}"; \ echo "This is some Q10MR11/FL12V text." | sed "s%${dc}%${rc}%g" dc=Q10MR11/FL12V rc=DELETED This is some DELETED text. Interesting...using the vertical bar as the regex separator worked where the % failed for me. I never hit this before, but like another poster, I always use "#" unless it conflicts in which case I use "@" or "|" instead. I don't see how this would be an issue *unless* you have jobs running in the background of this shell. Remember that "%" is semi-special to the shell, if you start a background job, you can kill it with kill %1 or whatever number shows up from the "jobs" command. However, it shouldn't do that unless you are using a built-in command like "fg" or "kill" and I suspect that is the only place that %number sequence is special. If you get an answer let us know, I was unable to replicate your problem, although I doubt I use the "-i" option once in a decade with sed. I sort of remembered it was there, but had to look to check operation (it takes a suffix). If you can still get the % to fail, just for grins try putting -e before the command. -- Bill Davidsen "We have more to fear from the bungling of the incompetent than from the machinations of the wicked." - from Slashdot -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
On Wednesday 01 April 2009 01:11:47 David Burns wrote: > On Tue, Mar 31, 2009 at 1:37 PM, Craig White wrote: > > subtitle...fun with sed > > > > I have a list of changes to make to a file... > > > > dc rc > > - --- > > 15T6145V DELETED > > NATL19502 DELETED > > Q10MR11/FL12V DELETED > > Q1500T3/CL120 DELETED > > > > and things work until I get to the 3rd item which has a forward slash > > and it fails to substitute with commands like below... > > > > sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv > > and > > sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv > > > > The latter producing error on screen... > > sed: -e expression #1, char 17: unknown option to `s' > > > > While the former simply doesn't complain but doesn't make the change > > either. > > > > Is there a way to coerce sed to identify & replace strings with a / > > inside? > > I don't think it is sed that is giving you a problem: > > $ echo "Q10MR11/FL12V "|sed "s|Q10MR11/FL12V|DELETED|" > DELETED He didn't use | he used /. You've inadvertently offered him the solution though. -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
Craig White wrote: On Tue, 2009-03-31 at 20:16 -0400, Todd Zullinger wrote: Craig White wrote: subtitle...fun with sed I have a list of changes to make to a file... dc rc - --- 15T6145VDELETED NATL19502 DELETED Q10MR11/FL12V DELETED Q1500T3/CL120 DELETED and things work until I get to the 3rd item which has a forward slash and it fails to substitute with commands like below... sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv and sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv The latter producing error on screen... sed: -e expression #1, char 17: unknown option to `s' While the former simply doesn't complain but doesn't make the change either. Hmm, it should work using a delimeter other than '/' or escaping the '/'. Escaping the '/' is a bit more of a pain than just changing delimeters, as long as you know that whatever delimeter you pick won't be in the strings you are substituting. It seems to work for me: $ dc="Q10MR11/FL12V"; rc=DELETED; echo "dc=${dc}"; echo "rc=${rc}"; \ echo "This is some Q10MR11/FL12V text." | sed "s%${dc}%${rc}%g" dc=Q10MR11/FL12V rc=DELETED This is some DELETED text. Interesting...using the vertical bar as the regex separator worked where the % failed for me. Thanks Craig You should be able to do: (so as long as ' is not part of the input stream) sed -i 's%'${dc}'%'${rc}'%g' ARsalesorderdetails.csv I personally use delimiters as # or | depending on the input string stream -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
Craig White wrote: subtitle...fun with sed I have a list of changes to make to a file... dc rc - --- 15T6145VDELETED NATL19502 DELETED Q10MR11/FL12V DELETED Q1500T3/CL120 DELETED and things work until I get to the 3rd item which has a forward slash and it fails to substitute with commands like below... sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv and sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv The latter producing error on screen... sed: -e expression #1, char 17: unknown option to `s' While the former simply doesn't complain but doesn't make the change either. Is there a way to coerce sed to identify & replace strings with a / inside? Craig The second fails because in the file where there is a '/' in the stream, sed sees more delimiters such as: s//Q1500T3/CL120 DELETED/g ^ (extra delimiter) and so fails. Your use of '%" as a sed delimiter works so as long as % is not part of the sed stream. -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
On Tue, 2009-03-31 at 20:16 -0400, Todd Zullinger wrote: > Craig White wrote: > > subtitle...fun with sed > > > > I have a list of changes to make to a file... > > > > dc rc > > - --- > > 15T6145VDELETED > > NATL19502 DELETED > > Q10MR11/FL12V DELETED > > Q1500T3/CL120 DELETED > > > > and things work until I get to the 3rd item which has a forward > > slash and it fails to substitute with commands like below... > > > > sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv > > and > > sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv > > > > The latter producing error on screen... > > sed: -e expression #1, char 17: unknown option to `s' > > > > While the former simply doesn't complain but doesn't make the change > > either. > > Hmm, it should work using a delimeter other than '/' or escaping the > '/'. Escaping the '/' is a bit more of a pain than just changing > delimeters, as long as you know that whatever delimeter you pick won't > be in the strings you are substituting. > > It seems to work for me: > > $ dc="Q10MR11/FL12V"; rc=DELETED; echo "dc=${dc}"; echo "rc=${rc}"; \ > echo "This is some Q10MR11/FL12V text." | sed "s%${dc}%${rc}%g" > dc=Q10MR11/FL12V > rc=DELETED > This is some DELETED text. Interesting...using the vertical bar as the regex separator worked where the % failed for me. Thanks Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
On Tue, 2009-03-31 at 14:11 -1000, David Burns wrote: > On Tue, Mar 31, 2009 at 1:37 PM, Craig White wrote: > > subtitle...fun with sed > > > > I have a list of changes to make to a file... > > > > dc rc > > - --- > > 15T6145VDELETED > > NATL19502 DELETED > > Q10MR11/FL12V DELETED > > Q1500T3/CL120 DELETED > > > > and things work until I get to the 3rd item which has a forward slash > > and it fails to substitute with commands like below... > > > > sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv > > and > > sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv > > > > The latter producing error on screen... > > sed: -e expression #1, char 17: unknown option to `s' > > > > While the former simply doesn't complain but doesn't make the change > > either. > > > > Is there a way to coerce sed to identify & replace strings with a / > > inside? > > > > I don't think it is sed that is giving you a problem: > > $ echo "Q10MR11/FL12V "|sed "s|Q10MR11/FL12V|DELETED|" > DELETED > > Perhaps bash is not resolving your use of the ${dc} and ${rc} > variables as you expect. Since you do not include the full string of > commands and I never use ${}, I don't know what the problem is. > Dave you could be right...my problem is I can't enclose the sed string in single quotes because the variables won't expand and I find that just doing this... sed -i "s|$dc|$rc|g" ARsalesorderdetails.csv fails and still leaves me with this... 1,6066,"Q1500T3/CL/120V",2," 6.99 ",2,,,"2007-01-09",1,,, so I'm strugging with various ways... sed -i "s|$(dc)|$(rc)|g" ARsalesorderdetails.csv # doesn't work or the curly braces to try to keep the string together Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
Craig White wrote: > subtitle...fun with sed > > I have a list of changes to make to a file... > > dc rc > - --- > 15T6145VDELETED > NATL19502 DELETED > Q10MR11/FL12V DELETED > Q1500T3/CL120 DELETED > > and things work until I get to the 3rd item which has a forward > slash and it fails to substitute with commands like below... > > sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv > and > sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv > > The latter producing error on screen... > sed: -e expression #1, char 17: unknown option to `s' > > While the former simply doesn't complain but doesn't make the change > either. Hmm, it should work using a delimeter other than '/' or escaping the '/'. Escaping the '/' is a bit more of a pain than just changing delimeters, as long as you know that whatever delimeter you pick won't be in the strings you are substituting. It seems to work for me: $ dc="Q10MR11/FL12V"; rc=DELETED; echo "dc=${dc}"; echo "rc=${rc}"; \ echo "This is some Q10MR11/FL12V text." | sed "s%${dc}%${rc}%g" dc=Q10MR11/FL12V rc=DELETED This is some DELETED text. -- ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp ~~ It is dangerous to be sincere unless you are also stupid. -- George Bernard Shaw (1856-1950) pgp9uORsvCOlA.pgp Description: PGP signature -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Re: sed substitution that contains forward slash
On Tue, Mar 31, 2009 at 1:37 PM, Craig White wrote: > subtitle...fun with sed > > I have a list of changes to make to a file... > > dc rc > - --- > 15T6145V DELETED > NATL19502 DELETED > Q10MR11/FL12V DELETED > Q1500T3/CL120 DELETED > > and things work until I get to the 3rd item which has a forward slash > and it fails to substitute with commands like below... > > sed -i "s%${dc}%${rc}%g" ARsalesorderdetails.csv > and > sed -i "s/${dc}/${rc}/g" ARsalesorderdetails.csv > > The latter producing error on screen... > sed: -e expression #1, char 17: unknown option to `s' > > While the former simply doesn't complain but doesn't make the change > either. > > Is there a way to coerce sed to identify & replace strings with a / > inside? > I don't think it is sed that is giving you a problem: $ echo "Q10MR11/FL12V "|sed "s|Q10MR11/FL12V|DELETED|" DELETED Perhaps bash is not resolving your use of the ${dc} and ${rc} variables as you expect. Since you do not include the full string of commands and I never use ${}, I don't know what the problem is. Dave -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines