sed query

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

sed query

Postby maxeaves » Wed Mar 02, 2011 3:41 pm

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
maxeaves
 
Posts: 63
Joined: Thu Oct 18, 2007 8:54 am

Postby maxeaves » Wed Mar 02, 2011 4:00 pm

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?
maxeaves
 
Posts: 63
Joined: Thu Oct 18, 2007 8:54 am

Postby nelz » Wed Mar 02, 2011 4:40 pm

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)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests