gnu-sed

Tiebreaker for same-length regex alternatives with same starting position

寵の児 提交于 2021-01-27 05:34:35
问题 Using GNU sed (with the -r flag for clarity), the following two substitutions on the input string ab give the same result: s/(.)(.)|(.)(.)$/\2\1\3\4/ and s/(.)(.)$|(.)(.)/\1\2\4\3/ both give ba . It would appear that the alternative (.)(.) (the one without $ ) succeeds in both substitutions, regardless of whether its position as the first or second alternative. Why is this the case? What is the tie-breaker for such alternatives? The POSIX specification of regular expressions specifies 1 the

Replace one capture group with another with GNU sed (macOS) 4.4

一笑奈何 提交于 2019-12-11 08:44:36
问题 I've looked around some other peripheral questions and haven't been able to find a solution to my problem, so I'm sorry if this is a duplicate to something I missed. Basically, I have the following GNU sed command: sed -E -imr 's/^(\w)+/(\w)+$/g' file which is supposed to replace the first word of a line with the last word of the line. The first regex ^(\w)+ works great and matches the first word of each line. The problem is that the command replaces that first word with the literal string (w

GNU sed, ^ and $ with | when first/last character matches

社会主义新天地 提交于 2019-12-11 01:54:13
问题 When doing a substitution that includes something like ^|. in the REGEXP sed doesn't match the null string at beginning of the pattern space if the first character matches. It also doesn't match the end if the last character matches. Why is that? Here are some examples using 123 as input (with the -r option): substitution expected output actual output comments s/^/x/g x123 x123 works as expected s/$/x/g 123x 123x works as expected s/^|$/x/g x123x x123x works as expected s/^|./x/g xxxx xxx

Sed gives: sed: can't read : No such file or directory

放肆的年华 提交于 2019-11-30 08:05:43
I have the following bash script which repeats for each image found. It needs to iterated over all html , css and js files, and replace all occurrences of an image within that file. for image in app/www/images-theme-dark/*.png do echo "installing icon" $image # extract filename from iconpath iconfile=$(basename $image) iconPath="images/"$(basename $image) # replace paths in all files containing icon paths find app/www -type f \( -name "*.html" -or -name "*.css" -or -name "*.js" \ -or -name "*.appcache" \) \ -exec sed -i '' -e 's|$iconPath|images-theme-dark/$iconfile|g' "{}" \; done However

Sed gives: sed: can't read : No such file or directory

感情迁移 提交于 2019-11-29 05:25:33
问题 I have the following bash script which repeats for each image found. It needs to iterated over all html , css and js files, and replace all occurrences of an image within that file. for image in app/www/images-theme-dark/*.png do echo "installing icon" $image # extract filename from iconpath iconfile=$(basename $image) iconPath="images/"$(basename $image) # replace paths in all files containing icon paths find app/www -type f \( -name "*.html" -or -name "*.css" -or -name "*.js" \ -or -name "*