Issue
I have a large file with many scattered file paths that look like
lolsed_bulsh.png
I want to prepend these file names with an extended path like:
/full/path/lolsed_bullsh.png
I'm having a hard time matching and capturing these. currently i'm trying variations of:
cat myfile.txt| sed s/\(.+\)\.png/\/full\/path\/\1/g | ack /full/path
I think sed has some regex or capture group behavior I'm not understanding
Solution
sed
uses POSIX BRE, and BRE doesn't support one or more quantifier +
. The quantifier +
is only supported in POSIX ERE. However, POSIX sed uses BRE and has no option to switch to ERE.
Use ..*
to simulate .+
if you want to maintain portability.
Or if you can assume that the code is always run on GNU sed, you can use GNU extension \+
. Alternatively, you can also use the GNU extension -r
flag to switch to POSIX ERE. The -E
flag in higuaro's answer has been tagged for inclusion in POSIX.1 Issue 8, and exists in POSIX.1-202x Draft 1 (June 2020).
Answered By - nhahtdh Answer Checked By - Gilberto Lyons (WPSolving Admin)