write script for more then 600 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting write script for more then 600 files
# 1  
Old 08-23-2009
write script for more then 600 files

Hi,
i have 600 or more file on my server and from this 600 files i want to make one file. i have written this script

SPATH=/etlstg/DAT
TPATH=/etlstg/DAT/DAT_PROCESSED
FILE_DATE=`TZ=CST+24 date +20%y%m%d`
a1=0
while [ $a1 -le 9 ]
do
a2=0
while [ $a2 -le 9 ]
do
a3=0
while [ $a3 -le 9 ]
do
a4=0
while [ $a4 -le 9 ]
do
cat $SPATH/dat$FILE_DATE_*_[$a1][$a2][$a3][$a4]* >> $TPATH/dat$FILE_DATE.txt

a4=`echo $a4+1|bc`
done
a3=`echo $a3+1|bc`
done
a2=`echo $a2+1|bc`
done
a1=`echo $a1+1|bc`
done

This script seems to work fine, but i m not able to validated it

I also want to maintain a log where i can enter the file count. can anyone help me to modify this script???
# 2  
Old 08-23-2009
There is probably a much simpler way to do that task. But here is a slightly simplified way using the builtin capabilities of Bash.
Code:
#!/bin/bash
SPATH=/etlstg/DAT
TPATH=/etlstg/DAT/DAT_PROCESSED
FILE_DATE=`TZ=CST+24 date +%Y%m%d`
F=$TPATH/dat$FILE_DATE.txt

for ((a1=0;  a1<10;  a1++)); do
  for ((a2=0;  a2<10;  a2++)); do
    for ((a3=0;  a3<10;  a3++)); do
      for ((a4=0;  a4<10;  a4++)); do
        echo cat $SPATH/dat${FILE_DATE}_*_[$a1][$a2][$a3][$a4]* >> $F
      done
    done
  done
done

Notice that %Y is what you want instead of 20%y.

Once you are have verified that it does what you expect, remove echo, delete the output file and run it again.


Wait! Come to think of it, I think you could replace those 4 loops with this:
Code:
for ((a=0;  a<10000;  a++)); do
    echo cat $SPATH/dat${FILE_DATE}_*_"$(printf "%04d" $a)"* >> $F
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to write a script that checks whether files are moving out of a directory.

I have a directory that has files going into it and moving out on a regular basis. The normal state of the directory would be to be empty. I need to write a script that will check to see if files are Not moving out of the directory. Any help would be most welcome. (4 Replies)
Discussion started by: RoBKoS
4 Replies

2. Shell Programming and Scripting

Script to open files and write into new one

Hello! I am a real beginner in scripting, so I am struggling with a really easy task! I want to write a script to concatenate several text files onto each other and generate a new file. I wanted the first argument to be the name of the new file, so: ./my_script.sh new_file file1.txt... (5 Replies)
Discussion started by: malajedala
5 Replies

3. UNIX for Dummies Questions & Answers

Script to break up file (write new files) in bash

Hello experts, I need help writing individual files from a data matrix, with each new file being written every time there is a blank line: From this cat file.txt col1 col2 col3 6661 7771 8881 6661 7771 8881 6661 7771 8881 col1 col2 col3 3451 2221 1221... (6 Replies)
Discussion started by: torchij
6 Replies

4. Shell Programming and Scripting

Need help to write a script for moving the log files to some other folder

Hi Experts, I want to write a script, based upon the following requirement 1) I am having 5 application $ cd logs $ ls -l drwxr-xr-x 2 natraj nat 5.0K Sep 20 10:25 one drwxr-xr-x 2 natraj nat 5.0K Sep 20 10:39 two drwxr-xr-x 2 natraj nat 1.5K Sep 20 10:58... (4 Replies)
Discussion started by: natraj005
4 Replies

5. UNIX for Dummies Questions & Answers

Create a shell script for write files with 2 parameters

Hello, I'm a newbie in shell script. So, i would like to create a shell script which take 2 IN parameters (PARAM1 and PARAM2). This script need to create 2 files as : I need to create this file /etc/apache2/sites-available/PARAM2 : <VirtualHost *:80> DocumentRoot "/home/PARAM1/www"... (0 Replies)
Discussion started by: chatlumo
0 Replies

6. UNIX for Dummies Questions & Answers

Not sure how to write a script to delete certain files?

I'm a total *nix newb so I really could use some help! :o I plan on running a cron job on my server that deletes some files and then backs up and emails the website for archival purposes. Before I get in too deep I'd like to remove some unnecessary files that phpThumb creates. I'm not sure... (4 Replies)
Discussion started by: Sinistral
4 Replies

7. Shell Programming and Scripting

Write a new file from 2 files as input to the script

Hi- I am hoping someone can give me some pointers to get me started. I have a file which contains some dn's .e.g file 1 cn=bob,cn=user,dc=com cn=kev,cn=user,dc=com cn=john,cn=user,dc=com I have a second file e.g. file.template which looks something like :- dn: <dn> objectclass:... (5 Replies)
Discussion started by: sniper57
5 Replies

8. Shell Programming and Scripting

write a script to compare two files

Hi all, i am new to unix,i have never worked on scripting and all,i am learning now and i have to write a script to compare two files. The requirement is like : in the first file i am searching for a word and after i get that word i have to select everything from the rest of the file and redirect... (34 Replies)
Discussion started by: usha rao
34 Replies

9. UNIX for Dummies Questions & Answers

SCO 5.0.7 Cron creates files with 600, need 644

Hi, I've searched and read, and searched and read some more; but I'm still not connecting the dots or understanding what I need to change. I have a script that creates a file. If I run it as root, the file gets created with 644 permissions like I want. That seems to make sense (at least I... (2 Replies)
Discussion started by: 65bit
2 Replies

10. Shell Programming and Scripting

Script with read/write Files

Hello, I am a Newbie in ksh Unix Script. So I must write a ksh/sh script who read character at a position in a File. So also it must read all the lines who belongs at these characters , then write these lines in a another File. Can you help me , or give little councils to advance with my... (5 Replies)
Discussion started by: steiner
5 Replies
Login or Register to Ask a Question