Unix questions - How automatically to number all the files of a repertory

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > October 2005 > How automatically to number all the files of a repertory





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 How automatically to number all the files of a repertory
guytou77

2005-09-30, 7:50 am

Hi,



How to make automatically to number by a SHELL script all the files present
in the repertory "/home/toto/"?

The files will be numbered in the following way of 1 to N:



1-***
2-***
3-***

....
..........
n-***



Thanks.



GUY


Ed Morton

2005-09-30, 7:50 am

guytou77 wrote:
> Hi,
>
>
>
> How to make automatically to number by a SHELL script all the files present
> in the repertory "/home/toto/"?
>
> The files will be numbered in the following way of 1 to N:
>
>
>
> 1-***
> 2-***
> 3-***
>
> ...
> .........
> n-***
>
>
>
> Thanks.
>
>
>
> GUY
>
>


This sounds a lot like homework, so don't expect to get a complete
answer, but here's some hints:

man mv
man <your shell> looking for arithemtic operators

and look at question 14 in the FAQ
(http://home.comcast.net/~j.p.h/cus-faq-2.html#14).

Ed.
John Gordon

2005-09-30, 5:56 pm

In <433d0548$0$7834$8fcfb975@news.wanadoo.fr> "guytou77" <mapasa59@wanadoo.fr> writes:

> How to make automatically to number by a SHELL script all the files present
> in the repertory "/home/toto/"?


Do you want the files renamed to include the number? Or do you just want
a numbered listing?

--
John Gordon "It's certainly uncontaminated by cheese."
gordon@panix.com

Thobias Vakayil

2005-10-03, 7:50 am

i=1
for file in `ls`
do
echo "$i-$file"
i=`expr $i + 1`;
done


Ed Morton wrote:

> guytou77 wrote:
>
>
> This sounds a lot like homework, so don't expect to get a complete
> answer, but here's some hints:
>
> man mv
> man <your shell> looking for arithemtic operators
>
> and look at question 14 in the FAQ
> (http://home.comcast.net/~j.p.h/cus-faq-2.html#14).
>
> Ed.




--
Thobias Vakayil
Alcatel Development India (ADI)
PH: 2349961/72/86 EXTN :7018
Stephane Chazelas

2005-10-03, 7:50 am

On Mon, 03 Oct 2005 16:21:38 +0530, Thobias Vakayil wrote:
> i=1
> for file in `ls`
> do
> echo "$i-$file"
> i=`expr $i + 1`;
> done

[...]

Wrong usage of command substitution.

Wrong quoting of variables.

Wrong usage of echo.

ls | awk '{print NR "-" $0}'

Which fails for file names containing newline characters.

awk '
BEGIN {
if (ARGV[1] == "[*]" && ARGV[2] == "*")
exit(0)
for (i = 2; i < ARGC; i++)
print i - 1 "-" ARGV[i]
exit(0)
}' [*] *

Which fails if the file list size exceeds the execve system call
argument size capacity.

Neither version outputs dot files.

--
Stephane
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com