Hi.
Quote:
Originally Posted by reborg
Code:
sed 's_/\([^/]+\)$_|\1_'
|
I needed to use "*" instead of "+". Some versions of
sed may need "-r" to use extended regular expressions, in which the parens also need to modified:
Code:
#!/bin/sh -
# @(#) user2 Demonstrate replacement of last specific character, sed.
sed --version | head -1
echo
echo " Original:"
echo "/home/apps/test/document" |
sed 's_/\([^/]+\)$_|\1_'
echo
echo " Modified:"
echo "/home/apps/test/document" |
sed 's_/\([^/]*\)$_|\1_'
echo
echo " Original with -r:"
echo "/home/apps/test/document" |
sed -r -e 's_/([^/]+)$_|\1_'
exit 0
Producing:
Code:
% ./user2
GNU sed version 4.1.2
Original:
/home/apps/test/document
Modified:
/home/apps/test|document
Original with -r:
/home/apps/test|document
There are (too) many versions of
sed, so one must know which version one is using. For example, if you were to leave the "\(", "\)" in the 3rd example, you would get an error message, "invalid reference \1", not very informative, at least not directly ... cheers, drl