Checking the directory and concatenate the data of all the log files in that dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking the directory and concatenate the data of all the log files in that dir
# 1  
Old 11-15-2008
Checking the directory and concatenate the data of all the log files in that dir

Hi Gurus,

I am new to unix and need your help to make a shell script. I have a requirement, would appreciate if you could please help me on it:

Requirement:
-------------

I will pass 2 parameters in shell script 1). Directory name say errors 2). file extension say .log
First of all this script should check whether the specified directory exist or not, if exists then it should return "true" otherwise "false"
If the directory exists then, i want to concatenate the data of all the files (with the extension as passed in the parameter) and return this concatenated data.

Please help.

Thanks,

Regards,
AS
# 2  
Old 11-15-2008
Hi,

After reading a bit i have made this script but not sure how far it is right. Please help.

echo $*
INFILE_DIR=$1
INFILE_EXT=$2
cd $XXIPO_TOP
if test -s $INFILE_DIR/*.INFILE_EXT; then
echo " "
echo "*** File Concatenation Started ***"
echo " "
for i in `ls -l $INFILE_DIR/*.INFILE_EXT | awk '{print $9}'
do
cat $i >> targetfilename
done

else
echo "*** File to be imported doesnot exist or has no data ***"
echo $INFILE_DIR/*.INFILE_EXT
exit 1
fi

Thanks.,
Regards,
AS
# 3  
Old 11-16-2008
this small code will do
Code:
if test -d $1 ; then
echo "DIR exist"
cd $1
echo "*** File Concatenation Started ***"
cat *$2>>consolidatefile
else
echo "false"
fi

# 4  
Old 11-16-2008
Thanks for your help Vidyadhar. i will test this script and will let u know if any issue faced.

Thanks alot..

Regards,
AS
# 5  
Old 11-16-2008
Hi Vidyadhar, this script is erroring out saying "fi is not expected". Please suggest.

Thanks,

Regards,
AS
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dig and concatenate all files yesterday then save it to another directory

I dont want to use for loop since it is using a lot of resources especially to a thousand files. Wanting to have a while? or something will find files that has been modifed or created yesteraday. View it. And search for soemthing and save it to a certain folder. for i in `find ./ -mtime... (3 Replies)
Discussion started by: invinzin21
3 Replies

2. Shell Programming and Scripting

Script to keep checking the directory for files.

Hello Folks, Looking for a script which can keep doing ls to the directories and once file landed to the directory then ,read the files do further calculation and exit. Kindly guide. Regards, Sadique (3 Replies)
Discussion started by: sadique.manzar
3 Replies

3. Shell Programming and Scripting

Concatenate 2 files data

Hi, I have one file as: $cat file1 abc pqr 123 def wxy 234 xyz ghi 567 and another file as $cat file2 345 456 987 I want the output of file2 to be appended in file1. And file 1 should look like: $cat file1 abc pqr 123 345 def wxy 234 456 xyz ghi 567 987 (6 Replies)
Discussion started by: Bhrigu
6 Replies

4. Shell Programming and Scripting

Checking in a directory how many files are present and basing on that merge all the files

Hi, My requirement is,there is a directory location like: :camp/current/ In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Discussion started by: srikanth_sagi
10 Replies

5. Shell Programming and Scripting

List no. of files in a directory/sub dir's and also an consolidated report as required

Need help on below query asap. Thanks. The below is the directory structure: /home/suren under /suren the following are the directories /bin /log /error /bin contains the following files abc.txt bcd.ksh cde.sh wer.ksh ghi (file with out any extension) /log contains the following... (1 Reply)
Discussion started by: sureng
1 Replies

6. Shell Programming and Scripting

Checking dir and files!

Hi Guys, I wrote a code which checks for the text and directory. If the path is incorrect than it should echo that particular path not found. I can create a different if statments but I want to do this in just one if statment with the use of "or" (||). I have succssfully executed this code but now... (2 Replies)
Discussion started by: dixits
2 Replies

7. Shell Programming and Scripting

Checking if the files in a directory have a txt extension

foreach file ($dir1/*) if ($file ~ *.txt) then echo "Skipping $file (is a txt file)" endif end that should work right guys? :confused: (15 Replies)
Discussion started by: pantelis
15 Replies

8. Shell Programming and Scripting

Checking for proper number of files in dir

Using Solaris 10 and sh. I have three files. mydirs.txt /dir1/dir2/dir3 /dir4/dir5/dir6 mydirshave.txt 1 2 mydirsshouldhave.txt 2 2 For each directory listed in mydirs.txt I should have the number of files equal to mydirshouldhave.txt. But using -ls |wc -l- on the dirs I get what... (2 Replies)
Discussion started by: crowman
2 Replies

9. Shell Programming and Scripting

home dir checking

Hi, I want suggestion about user home directories, checking. how i could calculate this. I have 200 Users. if home-dir-of-user1 > 250 MB -> print "OK" fi if home-dir-of-user1 > 500 MB > Print "Warning" fi if home-dir-of-user1 > 1000 MB > Print "Critical" fi Thanks, Bash (4 Replies)
Discussion started by: learnbash
4 Replies

10. Shell Programming and Scripting

Scripting help for rm log files from multiple dir

Hi, I'm quite new to scripting and need some help. I need to have one script that will check specific directories for files older than one month and then have the script delete them. I have written the script below but it only does one directory. I don't quite know how to make it so it... (7 Replies)
Discussion started by: morgadoa
7 Replies
Login or Register to Ask a Question