|
Home > Archive > Unix administration > August 2006 > Using SED to change a file name
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using SED to change a file name
|
|
| arthur.walker@gt.com 2006-08-10, 7:39 pm |
| All;
I am trying to use sed to change the a file name that I have placed in
a .netrc script, and am not having any luck.
Here is what I am trying to accomplish:
Take file named hawk, and change to hawk_yyyymmdd_time.txt
Every week I need to change the file to the most recent date. My date
function works fine, it is just how it appends the date to the file
name.
sed 's/put hawk_/put hawk_'$DATE'.txt/g' /export/home/awalker/.netrc >
/export/home/awalker/.netrc_tmp
I copy the .netrc_tmp file back to .netrc, and prefrom chmod 600 .netrc
The .netrc script is updated the first time correctly, i.e.
hawk_20060801_141644.txt
however, the next time I run the job the .netrc script name looks like
this:
hawk_20060801_151311.txt20060801_151305.txt
Any help would be greatly apprecaited.
| |
| Logan Shaw 2006-08-10, 7:39 pm |
| arthur.walker@gt.com wrote:
> I am trying to use sed to change the a file name that I have placed in
> a .netrc script, and am not having any luck.
See my answer in comp.unix.programmer.
Also, for future reference, it's not polite to post a message separately
to several newsgroups. Instead, you should post once and include the
entire set of newsgroups[1] in the one post. How you do this might vary
with the particular software you're using, but the usual way is to list
all the newsgroups in the same Newsgroups: header line.
The reason for this is that the answers you've already gotten in other
newsgroups will show up in all the groups you cross-posted to, thus
saving people the trouble of answering your question if it has already
been answered.
- Logan
[1] Keeping in mind the set of newsgroups you choose should be
limited, of course. Regardless of which method you use,
posting to 25 newsgroups is not appropriate.
| |
| Chris F.A. Johnson 2006-08-11, 1:31 am |
| On 2006-08-10, arthur.walker@gt.com wrote:
> All;
>
> I am trying to use sed to change the a file name that I have placed in
> a .netrc script, and am not having any luck.
>
> Here is what I am trying to accomplish:
>
> Take file named hawk, and change to hawk_yyyymmdd_time.txt
>
> Every week I need to change the file to the most recent date. My date
> function works fine, it is just how it appends the date to the file
> name.
>
> sed 's/put hawk_/put hawk_'$DATE'.txt/g' /export/home/awalker/.netrc >
> /export/home/awalker/.netrc_tmp
>
> I copy the .netrc_tmp file back to .netrc, and prefrom chmod 600 .netrc
>
> The .netrc script is updated the first time correctly, i.e.
> hawk_20060801_141644.txt
>
> however, the next time I run the job the .netrc script name looks like
> this:
>
> hawk_20060801_151311.txt20060801_151305.txt
sed "s/put hawk_.*/put hawk_$DATE.txt/" /export/home/awalker/.netrc > /export/home/awalker/.netrc_tmp
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| arthur.walker@gt.com 2006-08-11, 1:40 pm |
| Thanks for the suggestions everyone. Worked perfect.
|
|
|
|
|