Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sed query

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
maxeaves



Joined: Thu Oct 18, 2007 9:54 am
Posts: 63

PostPosted: Wed Mar 02, 2011 3:41 pm    Post subject: sed query Reply with quote

Dear all,

I've got a problem with a SED sequence....could somebody lend me some guidance please.

ls -d $media_path/$filename_search | sed 's/${filename_search}/cp "&" "INTRANSFER\\1.encodation.xml"/' | sh

I want to take a file called channel_dd-mm-yy.xml and copy it into a directory called INTRANSFER with the revised filename channel-dd-mm-yy.encodation.xml

Using simple reg.ex, I can get things to work

echo blahblah.xml | sed 's/.xml/.encodation.xml/'

Thanks



Max
Back to top
View user's profile Send private message
maxeaves



Joined: Thu Oct 18, 2007 9:54 am
Posts: 63

PostPosted: Wed Mar 02, 2011 4:00 pm    Post subject: Reply with quote

Found a fix for it although it isn't elegant...

target_filename_search=$(echo $filename_search | sed "s/.xml/.encodation.xml/")
echo $target_filename_search
cp $media_path/$filename_search $media_path/INTRANSFER/$target_filename_search

any thoughts on the first way to do it in sed?
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8378
Location: Warrington, UK

PostPosted: Wed Mar 02, 2011 4:40 pm    Post subject: Reply with quote

The shell treats ' and " differently, variables are only expanded inside ", so by using ' you are passing the literal $filename_search to sed instead of the value of the variable.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast