On Sun, Feb 12, 2017 at 08:06:28PM -0500, bruce wrote:
Hey guys.
Thanks for the delete replies..
Got a quick sed question now..
test file::
head -2 sed.dat
228d98f0_f16a_11e6_9544_1ad613f05f7b,1486934882
22b93712_f16a_11e6_a6ad_1ad613f05f7b,1486934883
want to simply truncate/search/replace the end of each line starting
with the ","
to get
228d98f0_f16a_11e6_9544_1ad613f05f7b
22b93712_f16a_11e6_a6ad_1ad613f05f7b
the following isn't working
sed -i 's/\,+\$//' sed.dat
sed -i 's/\,+$//' sed.dat
I'm sure it's simple/trivial...
Several problems. The sed's I know don't use extended RE syntax
and '+' is a repetition character of extended RE. Some sed's
might allow its use with the '-r' option. And maybe there are
some sed's that do use extended RE.
Comma is not typically a special character, so no need to escape.
In pattern matching by the shell, the '*' repetition character
does not reference the preceeding character. RE repetition
characters (* in basic and + and ? in extended) always refer
to repetitions of the preceeding character. Thus your pattern
(if and extended RE) would be looking for a string of commas,
NOT one comma followed by a string of any char.
Try something like "sed -r -i 's/,[0-9]+$//'".
or "sed -i 's/,[0-9]*$//'" or if uncertain they
will be digits, but certain they will not be
commas (i.e. you want to delete the last comma
onward) try "sed -i 's/,[^,]*$//'
Jon
--
Jon H. LaBadie jonfu(a)jgcomp.com