LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2004, 07:52 PM   #1
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Rep: Reputation: 15
Scripting?


I have some quistions about scripting.

First
How do I rename a file like this

logfile.log -> (todays date)lofile.log

where todays date is the output from date.

How can I do this in a script. The date must not be the output just the date of the day. Hope you understand.

One more qustion:

How do I add a line to the first line in a text file wihtout erasing the informaton within??
 
Old 06-14-2004, 08:29 PM   #2
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
Code:
#!/bin/bash
 
DATE=`date --iso-8601=date`
 
mv logfile.log "$DATE"-logfile.log
To the second question you might have to create a file with a line and then add the contents of another file to the new file and the delete the original and rename your newly created file. There may be a better way. I'm not really sure.
 
Old 06-14-2004, 10:46 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Re: Scripting?

Quote:
Originally posted by eXor
How do I add a line to the first line in a text file wihtout erasing the informaton within??
Like benjithegreat98 says, there's probably a better way, but

sed 'i \
text you want to insert' current_file > new_file

mv new_file current_file

might do.
 
Old 06-15-2004, 07:43 AM   #4
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Original Poster
Rep: Reputation: 15
thx digiot
it worked like a charm

thx benjithegreat98
but I did it in an other way.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
new to scripting mifan Linux - Newbie 2 08-17-2005 01:10 PM
another help with scripting?! ice99 Programming 2 08-09-2005 09:56 AM
Need help scripting Tamara Programming 7 06-06-2005 03:06 AM
Scripting Help Please Jazinator Linux - Newbie 7 10-17-2004 07:35 PM
scripting bforest Linux - Newbie 4 05-11-2004 03:45 AM


All times are GMT -5. The time now is 02:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration