Help using awk and bash script to copy and rename lots of index.htm files

Help using awk and bash script to copy and rename lots of index.htm files

Post by Gary Nielso » Wed, 06 May 1998 04:00:00



Hi, all:

I am trying to figure out a way to accomplish the following:

1) Find all index.htm files in all subdirectories starting from the
/extra
2) Copy each index.htm file in its directory to an htm file with today's
day
abbreviated as the filename, (as in tue.htm today, wed.htm tomorrow...)
3) Make sure the date is all lowercase.
4) Run this script daily from a cron job.

I am new to shell scripting and awk. I figure I need to get the day by
doing:

        date | nawk '{print $1}'

get the date into a variable,
do a find for all index.htm files under /extra
and then pipe a cp in each directory, as in:

#find /extra/ -name index.htm -print | cp index.htm tue.htm

I am having a hard time capturing the day from today's date in a
variable outside
awk to use in the rest of the script and making sure it's all lowercase.
Awk returns
Tue not tue.

Any help much appreciated. Please email me as well. I have gotten some
awk stuff to
work and it is a big timesaver for sure!

Gary
C*te NC

 
 
 

Help using awk and bash script to copy and rename lots of index.htm files

Post by Charles Dem » Thu, 07 May 1998 04:00:00




Quote:>Hi, all:

>I am trying to figure out a way to accomplish the following:

>1) Find all index.htm files in all subdirectories starting from the
>/extra
>2) Copy each index.htm file in its directory to an htm file with today's
>day
>abbreviated as the filename, (as in tue.htm today, wed.htm tomorrow...)
>3) Make sure the date is all lowercase.
>4) Run this script daily from a cron job.

>I am new to shell scripting and awk. I figure I need to get the day by
>doing:

>        date | nawk '{print $1}'

>get the date into a variable,

use back quotes and assign it, but you have no need to here.

filename=`date | gawk '{print tolower($1) ".htm"}'`

Then use it as $filename or whatever you wanted to call it.

Quote:>do a find for all index.htm files under /extra
>and then pipe a cp in each directory, as in:

>#find /extra/ -name index.htm -print | cp index.htm tue.htm

If that works, then replace the tue.htm with this:

`date|gawk '{print tolower($1) ".htm"}'`

FWIW, I don't know if nawk has a tolower function, but I'd bet it does.

Quote:>I am having a hard time capturing the day from today's date in a
>variable outside
>awk to use in the rest of the script and making sure it's all lowercase.
>Awk returns
>Tue not tue.

use the tolower function within gawk (I prefer gawk) to change that,
and might as well stick on the .htm part, since it's so easy.
That will give you the filename you wanted.
As shown, there's no need to capture the day in a variable, so

don't bother.  :-)

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.


 
 
 

Help using awk and bash script to copy and rename lots of index.htm files

Post by Bruce Fountai » Thu, 07 May 1998 04:00:00



> Hi, all:

> I am trying to figure out a way to accomplish the following:

> 1) Find all index.htm files in all subdirectories starting from the
> /extra
> 2) Copy each index.htm file in its directory to an htm file with today's
> day
> abbreviated as the filename, (as in tue.htm today, wed.htm tomorrow...)
> 3) Make sure the date is all lowercase.
> 4) Run this script daily from a cron job.

> I am new to shell scripting and awk. I figure I need to get the day by
> doing:

>         date | nawk '{print $1}'

You don't really need to use awk here. Try this:

day=`date +%a | tr '[A-Z]' '[a-z]'`

Quote:> get the date into a variable,
> do a find for all index.htm files under /extra
> and then pipe a cp in each directory, as in:

> #find /extra/ -name index.htm -print | cp index.htm tue.htm

Maybe something like this:

for f in `find /extra -name index.htm -print`
do
   cp $f `dirname $f`/$day.htm
done

Regards,

Bruce

+--------------------------------------------------------------------------+
| Bruce Fountain                 NEC Australia - New Product Development   |

+--------------------------------------------------------------------------+

 
 
 

1. Copy files using filenames from text files with shell script or bash script

How can I do this????

I have the file "lista.txt", and this file have the next information:
     one.txt
     two.txt
     five.txt
    six.txt
-------------------
This files exist in the same directory that "list.txt", I would like to
copy this files to other directory

Using Windows the batch file would be like this:  for /f "tokens=*" %i
in (list.txt) do copy "%i" destdir\

How can I do something like that in REDHAT??

Best Regards

2. pgcl-2.5.70-1

3. Matrox Mystique ands X.

4. Net access through USB or PCI ethernet card

5. index.html, index.htm, etc.

6. CD-RW error: status=0x51 error=0x30

7. Substituting :: for __ in every htm file, and rename htlml file

8. turbolinux

9. server does not find index.htm

10. Apache & index.htm

11. Is it possible to have index.htm load when the is a hit on welcome.html?

12. how to make something other than index.htm the default web page?

13. My apache don`t load index.htm at start :(