LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2004, 12:23 PM   #1
BlkPoohba
LQ Newbie
 
Registered: Aug 2004
Location: NJ
Distribution: FC1
Posts: 1

Rep: Reputation: 0
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/'
 
Old 08-25-2004, 02:00 PM   #2
bastard23
Member
 
Registered: Mar 2003
Distribution: Debian
Posts: 275

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed -f: error nano_mag Linux - Newbie 3 05-15-2005 07:51 PM
sed error message: extra characters after the command. nano_mag Linux - General 3 05-15-2005 01:00 AM
sed substitution conditional frostillicus Linux - Newbie 3 04-17-2005 12:36 AM
process substitution jk3us Linux - Software 1 12-02-2004 04:34 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration