LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 11-18-2009, 07:05 AM   #1
rattlesnakejoe
LQ Newbie
 
Registered: Oct 2008
Posts: 14

Rep: Reputation: 0
sed replacing patterns with back quoted command


Hi,

I have n number of files by name something*.py...i want to replace in all the *.py files, a pattern "1r1z-a" by the last line of its own file

thus, i wrote this sed script


for i in *.py; do sed 's:1r1z-a:'`tail -1 $i`':g' $i; done

But this is not working, "sed: -e expression #1, char 15: unterminated `s' command" is the error message

Plz help
 
Old 11-18-2009, 07:32 AM   #2
indiajoe
Member
 
Registered: Jan 2009
Location: India
Distribution: Porteus atma
Posts: 84

Rep: Reputation: 21
Use double quotes

Hi
Use double quotes (") instead of (')
Code:
for i in *.py; do sed "s:1r1z-a:`tail -1 $i`:g" $i; done
-Cheers
indiajoe
 
Old 11-18-2009, 09:12 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Note that back-tics are deprecated----the preferred construct is $(command)

Quoting:

' is the hard quote---it stops the shell from action on anything inside.

" is the soft quote---allows the shell to act on specific things--most notably expanding a variable--eg $varname
 
  


Reply



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
ssh remote command preserve quoted argument honestiron Programming 7 09-18-2009 12:23 PM
SED how to find multiple patterns on a single line yaazz Programming 9 07-31-2009 04:20 AM
how to use sed to delete mutiple string patterns from apache access log matyu Programming 3 01-05-2008 11:42 PM
Bash: how do I pass a double quoted string to a command? Nylex Programming 8 04-18-2007 09:36 AM
Remembering patterns and printing only those patterns using sed bernie82 Programming 5 05-26-2005 05:18 PM

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

All times are GMT -5. The time now is 05:20 PM.

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