cp a file to named date
so I have a log that spits out lines in the form of
Transferring file `1MIN_TEST01.mov' and i wish to have only 1MIN_TEST01.mov the Base File Name and finally i wish to have that log named the date so if today is jan 30 2013 - 013013.txt here is what i have <code> #!/bin/bash ### this is a xample line from log:: Transferring file `1MIN_TEST01.mov' ## ~/log/\f_h_logfilea.txt #h="Transferring file `1MIN_TEST01.mov'" ####################### #2day=$(date)+%m%d%y #2day=$(`date +%y%m%d`) d=`date +%m%d%y` sed 's/Transferring file//g' ~/\log/\f_h_logfilea.txt > ~/\log/\f_h_logfile4a.txt sed "s/\`//g" ~/\log/\f_h_logfile4a.txt > ~/\log/\f_h_logfile4b.txt sed "s/'//g" ~/\log/\f_h_logfile4b.txt > ~/\log/\f_h_logfile4c.txt sed "s/ //g" ~/\log/\f_h_logfile4c.txt > ~/\log/\f_h_logfilefin.txt echo $d ##cp ~/\log/\f_h_logfilefin.txt ~/\log/\f_h_logfilefin.txt+`date +%m%d%y` cp ~/\log/\f_h_logfilefin.txt ~/\log/\$d.txt </code> now this will echo 013013 but the file that is cp'ed is named $d.txt I am ever so confused how echo $d can be 013013 ( provided the day is jan 30 2013 and the file name is literal $d.txt any help is appreciated. also -- likely there is a better means of sed .. i just keep running it through and cleaning it up my thinking was those 'versions' f_h_logfile4a.txt f_h_logfile4b.txt f_h_logfile4c.txt f_h_logfile4fin.txt just get over written and i have a tidy 013013.txt |
If you intend to add code tags manually, place them with [] and not <>, ie: [CODE]...[/CODE].
Also, it is better to use the $HOME env var instead of the ~ when referring your home directory within a script. This ensures it gets expanded correctly. Quote:
These can be replaced with (I've used the , as my delimiter): Code:
sed -i "s,Transferring file \`\(.*\)',\1," $HOME/log/f_h_logfilea.txt Quote:
Code:
cp ~/\log/\f_h_logfilefin.txt ~/\log/\$d.txt After running the above sed command, simply move the log file to the new name: Code:
mv $HOME/log/f_h_logfilea.txt $HOME/log/$d.txt Code:
#! /bin/bash |
thanks
1st thanks for the note about code tags...
and opps on me ... i ahve just seen how one may ( # gadget in interface ) mark code. and yep that works much cleaner thanks for the word about use of $HOME , did not know that one and I see the sed is working as sed -i "s,Transferring file \`\(.*\)',\1," I struggle to understand it part by part . what is the ,1, doing? also I may need additionally to sed OUT Making directory `trashbox' much thanks I love this community - |
The command:
Code:
sed -i "s,Transferring file \`\(.*\)',\1,"
Hope I've explained it properly so you can sed out the other stuff. |
thanks
Brother towheedm,
I offer High Thanks for your Lucid and detailed explanation.:hattip: To your credit - i understand , i grow. If ever in cincinnati - I am buying yall a beverage of choice.:) that matter of \1 - Replace the old pattern with the first back-reference (remembered pattern), i never read that in any of my investigation nor the matter of as back-references in RegEx. sed remembers whatever pattern is inside the brackets. The best part about being shown - is it enables one to learn more on one's own. wonderful thanks again |
using the , as my delimiter, is now my personal preference as well
|
Here are two links on back-references:
http://www.grymoire.com/Unix/Sed.html#uh-4 http://www.grymoire.com/Unix/Regular.html#uh-10 |
All times are GMT -5. The time now is 10:21 AM. |