----- Original Message -----
From: Steve Youngs <[EMAIL PROTECTED]>
To: Linux-Newbie <[EMAIL PROTECTED]>
Sent: Tuesday, March 21, 2000 7:03 PM
Subject: Re: shell script question
> * Jack Barnett <[EMAIL PROTECTED]> writes:
>
> > I am not very good with bourne shell scripts, but above you
> > increment LOOP with
>
> > LOOP=$[LOOP + 1]
>
> > why won't it work if you do a
>
> > FILE=$[FILE + 1]
>
> Because the contents of FILE is '$1' which is expanded to the first
> positional parameter of the command line. The command line as I
> stated was 'scriptname *', which expands to all the files in the
> current directory.
Got ya.
>
> So, for example, if the directory contains these files...
> aaa, bbb, ccc, ddd & eee
>
> scriptname * would expand to...
> scriptname aaa bbb ccc ddd eee
>
> and the contents of FILE is $1 which is 'aaa'. What I want to do is
> increment FILE from $1 (aaa) to $2 (bbb), then $3 (ccc) and so on.
>
> What you have suggested (FILE=$[ FILE +1 ]) the first time through the
> loop FILE would contain 'aaa', but the next time it would contain '1',
> then '2' and so on.
>
> > Also, isn't this statement clobbing your $FILE?
>
> > cat $FILE | tr "\r" "\n" > $FILE
>
> Nope, Linux handles it in its stride. :-)
Cool, if I tried something like that on Solaris it would be clobbered in an
instanct. Nice to know Linux is "thinking ahead" : )
>
> > If the filenames are numbered 1, 2, 3, 4; can't you just use the
> > LOOP variable?
>
> Unfortunately, the files aren't named 1 2 3 4 etc. With what I want
> to do, I won't know the filenames beforehand.
>
> > Here is a quick perl script that might work for you
>
> > #!/usr/bin/perl -w
>
> > $directory = "./";
> > @ls = `ls $directory`;
>
> > foreach(@ls)
> > { chop($_);
> > system ("cat $_ | tr \"\r\" \"\n\" > $_.output");
> > }
>
> That looks interesting, I can't comment on it because I don't know the
> first thing about perl scripting. :)
directory is a variable
@ls is an arrary that contains ALL files in $directory
For each element in the @ls arrary (each filename) it runs the system
command
cat current_file | tr "\r" "\n" > current_file.output
$_ is the variable for current file.
I seen you have gotten a ton of answer so I won't go further into this, but
assume one of the other 100 emails to the group about this got it
staightened out.
Jack
>
> Thanks for your help
>
> ===========================
> Want to really learn Linux?
> ... Install Slackware
> ===========================
>
> --
> |---<Regards, Steve Youngs>-------------------------------------|
> | Genius is the ability to |
> | reduce the complicated to the simple |
> |------------------------------------<[EMAIL PROTECTED]>---|
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to [EMAIL PROTECTED]
> Please read the FAQ at http://www.linux-learn.org/faqs
>
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs