| View previous topic :: View next topic |
| Author |
Message |
maxeaves
Joined: Thu Oct 18, 2007 9:54 am Posts: 63
|
Posted: Wed Mar 02, 2011 3:41 pm Post subject: sed query |
|
|
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 |
|
 |
maxeaves
Joined: Thu Oct 18, 2007 9:54 am Posts: 63
|
Posted: Wed Mar 02, 2011 4:00 pm Post subject: |
|
|
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 |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 8002 Location: Warrington, UK
|
Posted: Wed Mar 02, 2011 4:40 pm Post subject: |
|
|
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. _________________ Unix is user-friendly. It's just very selective about who it's friends are. |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|