Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-03-2003, 02:32 PM
|
#1
|
LQ Newbie
Registered: Aug 2003
Posts: 8
Rep:
|
bash script - incrementing a filename in a script
what is the best way to increment a filename in a bash script so that the filename is different each time the script is run and file is saved? ie. filename+1, filename+2, etc. example used in tar backup. 
|
|
|
08-03-2003, 04:43 PM
|
#2
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
filename` date|awk 'OFS="."{print $2,$3,$6,$4}'`
Makes a filename like this:
filenameAug.3.2003.16:46:02
|
|
|
08-03-2003, 09:54 PM
|
#3
|
LQ Newbie
Registered: Aug 2003
Posts: 8
Original Poster
Rep:
|
Response
Thanks, dude (or dudette?)
I really appreciate it.
And, I really do plan on learning this stuff.
Thanks.
|
|
|
08-03-2003, 11:05 PM
|
#4
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Just a suggestion ... if you replace
date
in the script with
date +%Y%m%d-%H%M%S
you save yourself the awk'ing
and get a more easily (logically)
sortable set of filenames... and save
yourself the ":" in filenames, which
scp, for instance, doesn't like :}
Cheers,
Tink
|
|
|
08-04-2003, 11:06 PM
|
#5
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
Yeah Tinksters is better. Except for that "weird European, puttin the year first" stuff. :P
Maybe:
date +%m%d%Y-%H%M%S
|
|
|
08-05-2003, 11:45 AM
|
#6
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep: 
|
That's not European.
In Europe (well, at least in The Netherlands) we use dd-mm-yyyy.
However, when sorting alphabetically yyyy-mm-dd is nicer I think.
Last edited by Hko; 08-05-2003 at 11:48 AM.
|
|
|
08-05-2003, 04:01 PM
|
#7
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Quote:
Originally posted by slapNUT
Yeah Tinksters is better. Except for that "weird European, puttin the year first" stuff. :P
Maybe:
date +%m%d%Y-%H%M%S
|
date +%Y%m%d-%H%M%S
That's not European, that's logical :} ... think
about it for a second. Once you have a date
range of more than a year it's stupid to sort
by months first. "My way" is also the way dates
are represented internally in all major SQL
databases, too.
Cheers,
Tink
Last edited by Tinkster; 08-05-2003 at 04:05 PM.
|
|
|
08-05-2003, 07:28 PM
|
#8
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
It was a joke!
But since you brought it up; you don't have to put the year first in the file name to sort by the year.
Code:
From man sort:
-k, --key=POS1[,POS2]
start a key at POS1, end it at POS 2 (origin 1)
That lets you sort filenames starting from any position you choose.
|
|
|
08-05-2003, 07:33 PM
|
#9
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Yes, you could ... or you could stick with the
logical, straightforward approach and then use
sort if you need something different ;)
Cheers,
Tink
|
|
|
08-05-2003, 08:06 PM
|
#10
|
LQ Newbie
Registered: Aug 2003
Posts: 8
Original Poster
Rep:
|
you guys can end this, now.
|
|
|
08-05-2003, 11:58 PM
|
#11
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
Quote:
Posted by Tinkster
Yes, you could ...
|
Thank you benevolent <cough> guru. I'm done.
|
|
|
All times are GMT -5. The time now is 06:13 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|