 |
|
 |
|
|
 |
Pls help with Unix shell question |
 |
 |
|
|
03-05-04 03:34 PM
Hi all,
Not having worked with Unix script for a while, suddenly, I
have a need. The only thing I can do on Unix now is "vi", which I guess I
will never forget.
I have a bunch of files, ending with ".data" in a Unix directory, which I
want to process in date order with a program. I recall doing
something similar in the old days. Does anyone have an example?
Thanks,
Bill
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-05-04 03:34 PM
["Followup-To:" header set to comp.unix.misc.]
On Fri, 05 Mar 2004 15:06:46 GMT, wl wrote:
> Hi all,
>
> Not having worked with Unix script for a while, suddenly, I
> have a need. The only thing I can do on Unix now is "vi", which I guess I
> will never forget.
>
> I have a bunch of files, ending with ".data" in a Unix directory, which I
> want to process in date order with a program. I recall doing
> something similar in the old days. Does anyone have an example?
It probably will depend on which date, creation, updated, .....
you could use find to get a list and if you want only files with a key
word you might need xargs.
http://groups.google.com/advanced_group_search
find xargs in the first box
*linux* in Newsgroup, U need 2 use *, pick English
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-05-04 04:36 PM
On Fri, 05 Mar 2004 15:06:46 +0000, wl wrote:
> Hi all,
>
> Not having worked with Unix script for a while, suddenly, I
> have a need. The only thing I can do on Unix now is "vi", which I guess I
> will never forget.
>
> I have a bunch of files, ending with ".data" in a Unix directory, which I
> want to process in date order with a program. I recall doing
> something similar in the old days. Does anyone have an example?
Assuming that you don't have any newline characters in your filenames,
this is easy.
The clues you need are
1) The shell will expand *.data into a list of files.
2) ls -t will sort files into time order. You might need '-u' or '-a'
depending on which time you want. Note well that Unix does not store the
'Creation' time. You might want '-r' as well.
3) The shell has 'while' loops.
Put this together and you get
ls -t *.data | while read filename
do
myprogram $filename
done
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-05-04 04:36 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
wl <bli01@yahoo.com> wrote:
[..]
> I have a bunch of files, ending with ".data" in a Unix directory, which I
> want to process in date order with a program. I recall doing
> something similar in the old days. Does anyone have an example?
for f in `ls -atr *.data`
do
<something with> $f
done
Hint:
man ls
- --
Michael Heiming (GPG-Key ID: 0xEDD27B94)
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD4DBQFASKGkAkPEju3Se5QRAnpIAKCtOGlOADWl
NV3PgUu12/4jH3oC3QCXYJNB
9/OQqkVrvlKCHtbvorwJxw==
=ku4g
-----END PGP SIGNATURE-----
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-05-04 05:34 PM
In article <aI02c.33676$hm4.26678@newsread3.news.atl.earthlink.net>, "wl" <bli01@yahoo.com>
writes:
> Hi all,
>
> Not having worked with Unix script for a while, suddenly, I
> have a need. The only thing I can do on Unix now is "vi", which I guess I
> will never forget.
>
> I have a bunch of files, ending with ".data" in a Unix directory, which I
> want to process in date order with a program. I recall doing
> something similar in the old days. Does anyone have an example?
>
> Thanks,
> Bill
>
>
maybe you want
ls -t *.data | program
ls -lt
shows how it is sorted.
ls -ltr
sorts backwards.
Man pages:
man ls
--
Michael Tosch
IT Specialist
HP Managed Services Germany
Phone +49 2407 575 313
Mail: michael.tosch@hp.com
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-05-04 05:34 PM
On Fri, 05 Mar 2004 at 15:49 GMT, Michael Heiming wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> wl <bli01@yahoo.com> wrote:
> [..]
>
>
> for f in `ls -atr *.data`
This breaks is there are spaces in the file names. Use:
ls -atr *.data | while IFS= read -r f
Of course, this will not work if there are newlines in any of the
file names. But I would consider that a broken file system.
> do
><something with> $f
> done
>
> Hint:
> man ls
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-05-04 06:34 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
> On Fri, 05 Mar 2004 at 15:49 GMT, Michael Heiming wrote:
Hi Chris!
> This breaks is there are spaces in the file names. Use:
> ls -atr *.data | while IFS= read -r f
> Of course, this will not work if there are newlines in any of the
> file names. But I would consider that a broken file system.
Yep, albeit I'd call using spaces in filenames broken, sure most
*nix FS will handle it just fine, albeit it requires lots of
quoting in scripts and isn't IMHO worth the trouble.
- --
Michael Heiming (GPG-Key ID: 0xEDD27B94)
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFASL82AkPEju3Se5QRAil/AKCxrrfd1F0GUGZbXE3W2UrBXdpJ4ACgxpAM
lQqRoTqDCPAsWVsu10o4OjM=
=xPR1
-----END PGP SIGNATURE-----
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-06-04 01:33 PM
In article <ovea2c.n3l.ln@news.heiming.de>,
Michael Heiming <michael+USENET@www.heiming.de> wrote:
...
>
>Yep, albeit I'd call using spaces in filenames broken, sure most
>*nix FS will handle it just fine, albeit it requires lots of
>quoting in scripts and isn't IMHO worth the trouble.
Unfortunately, spaces in filenames have become a fact of life, and cannot
be ignored. The operative question is: Does Windows (where most of these
problems originate) allow filenames with newlines? Luckily, I believe the
answer is no.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-06-04 01:33 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[ Followup-To: comp.unix.shell ]
Kenny McCormack <gazelle@yin.interaccess.com> wrote:
> In article <ovea2c.n3l.ln@news.heiming.de>,
> Michael Heiming <michael+USENET@www.heiming.de> wrote:
> ...
> Unfortunately, spaces in filenames have become a fact of life, and cannot
> be ignored. The operative question is: Does Windows (where most of these
Luckily not on my systems, so I can easily ignore the problem.
> problems originate) allow filenames with newlines? Luckily, I believe the
> answer is no.
Don't know, I don't do "M$ Windows".
;)
- --
Michael Heiming (GPG-Key ID: 0xEDD27B94)
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFASc2sAkPEju3Se5QRAjOnAKDXNsG63MEt
GdMlvQD5U8BVQI9pSQCgjD8n
+TwqRnL4gBzqM57ecmHmqMA=
=WIQ5
-----END PGP SIGNATURE-----
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Pls help with Unix shell question |
 |
 |
|
|
03-07-04 05:33 AM
Hi Bill:
You could try a script something like the following:
----------------------------------------------------
#! /bin/sh
for x in `ls -t *.data`
do
echo "Processes go here"
done
----------------------------------------------------
Note that the "`" quote character is the "backquote" or "backtick"
character on the same key as the tilde "~" character. (Should be
upper left corner of the keyboard.)
An alternative format for:
for x in `ls -t *.data`
at least for the Korn and Bash shells, but not the Bourne shell, is:
for x in $(ls -t *.data)
The "ls" command can display and sort by all three times stored in
each file's inode. The date/times are:
- last Access Date/Time (last time file was accessed/read)
- last Change Date/Time (last time file was modified)
- last Inode Change Date/Time (i.e.: changed files permissions or
ownership or date/time (via "touch" command) or number of links
or Group ownership or disk storage block numbers. Those are
the only actions I can think of that changes the inode but not
the file's contents.)
The "ls" command can display files according to these three times.
The invocation would be:
- ls -t # Last Change Time
- ls -tu # Last Access Time
- ls -tc # Last Inode Change Time
You can pick the switches that best fit your "process in date order"
requirement.
Note that most books and articles STILL INCORRECTLY STATE that a
file's inode contains the original Creation Date. UNIX does not
store that date, they store the Last Change date instead. (In the
case where a file is never modified, the Last Change Date is also the
file's Creation Date.)
Hope this helps. If not, feel free to ask via email (for
clarifications) if you would like to, since I haven't read newsgroups
very much these past few years.
Ross
wl wrote:
> Hi all,
>
> Not having worked with Unix script for a while, suddenly, I
> have a need. The only thing I can do on Unix now is "vi", which I
> guess I will never forget.
>
> I have a bunch of files, ending with ".data" in a Unix directory,
> which I
> want to process in date order with a program. I recall doing
> something similar in the old days. Does anyone have an example?
>
> Thanks,
> Bill
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 02:28 AM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|