sed substitution error
]$ for FILE in *;do NEWFILE=`echo $FILE | sed -e s/\w-(\w+)-.*/$1/`;echo -e $NEWFILE;done
-bash: command substitution: line 1: syntax error near unexpected token `(' -bash: command substitution: line 1: `echo $FILE | sed -e s/\w-(\w+)-.*/$1/' -bash: command substitution: line 1: syntax error near unexpected token `(' -bash: command substitution: line 1: `echo $FILE | sed -e s/\w-(\w+)-.*/$1/' -bash: command substitution: line 1: syntax error near unexpected token `(' -bash: command substitution: line 1: `echo $FILE | sed -e s/\w-(\w+)-.*/$1/' |
s/\w-(\w+)-.*/$1/ needs to be quoted with a ' (single quote) on each side of the expression:
's/\w-(\w+)-.*/$1/' should work. Except that we are using sed, not perl. So something closer to what you need is: 's/\w-\(\w\+\)-.*/\1/' Bash is parsing your sed expression and hence the error prefix of "-bash: command substitution:" . You need to escape it out with the single quotes or escape every meta character with a back slash. Plus sed looks for \( and \1 after it has been escaped, not perlre's ( and $1 repectively. http://pegasus.rutgers.edu/~elflord/unix/sed.html Hope this helps, chris PS I have been corrupted by perl. Use the available tool you are most familiar with. PPS Does anyone know of a sed script to convert perl regexs to sed? Cause that would be cool. |
All times are GMT -5. The time now is 03:00 AM. |