----- Original Message -----
From: Steve Youngs <[EMAIL PROTECTED]>
To: Linux Newbie <[EMAIL PROTECTED]>
Sent: Tuesday, March 21, 2000 4:08 AM
Subject: shell script question


> Hey People
>
> I'm having a problem with a bash shell script that I'm hoping someone
> here can help me with.
>
> The script is supposed to convert ^M to ^J in all the files in a
> directory.  The script is invoked with 'scriptname *'.  The thing that
> I just can't nut out is how to increment the variable that represents
> the filename.
>
> Here's what I have..
>
> ,----[ Le Script ]
> | #! /bin/bash
> |
> | LOOP_TIMES=$#
> | LOOP=1
> | FILE=$1
> |
> | while [ $LOOP -le $LOOP_TIMES ]; do
> |     cat $FILE | tr "\r" "\n" > $FILE
> |     somehow increment $FILE from $1 to $2, $3, $4 etc up to $#
> |     LOOP=$[ LOOP + 1 ]
> | done
> `----
>
> I know the answer will be something really simple and easy, I just
> can't think of it. :-(

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]


Also, isn't this statement clobbing your $FILE?

cat $FILE | tr "\r" "\n" > $FILE

If the filenames are numbered 1, 2, 3, 4; can't you just use the LOOP
variable?

(Sytnax is probably wrong)

#! /bin/bash

LOOP_TIMES=$#
LOOP=1
FILE=$1

while [ $LOOP -le $LOOP_TIMES ]; do
    cat $LOOP | tr "\r" "\n" > "$LOOP.new"
    LOOP=$[ LOOP + 1 ]
 done

Which would run all files in the directory (assuming the file names start at
1)

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");
 }

This will take ALL files in directory (including binary and data, opps) and
run then though the tr command and put the output in the same file name but
with .output at the end of it.  You might not need the chop command, I
forget.  Also check the syntax, and make sure all files in the directory are
plain ASCII text files.  Oh yea, make a backup first and use at your own
risk.


> --
> |---<Regards, Steve Youngs>-------------------------------------|
> |     It's a funny thing about life; if you refuse to accept    |
> |          anything but the best, you very often get it         |
> |------------------------------------<[EMAIL PROTECTED]>---|

Does that include the job market?  My job sucks they stuff me in a hole and
force me to work with NT, yuck.

Anyways, hope that helps. Let me know if you need it to do something else.

Jack





>
> -
> 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

Reply via email to