The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split file into multiple files depending upon first 4 digits deepakgang Shell Programming and Scripting 4 04-08-2008 10:21 PM
Ksh Storing Multiple Files and reading each line in each file. developncode UNIX for Dummies Questions & Answers 1 04-08-2008 01:44 PM
Executing Multiple .SQL Files from Single Shell Script file anushilrai Shell Programming and Scripting 3 04-07-2008 07:09 AM
Help Needed : Split one big file to multiple files monicasgupta Shell Programming and Scripting 5 03-03-2008 04:09 PM
how to divide single large log file into multiple files. kamleshm Shell Programming and Scripting 1 01-15-2008 04:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-23-2008
Registered User
 

Join Date: Jan 2008
Posts: 1
Question why is it workin for 1 file , but not for multiple files?

Hi , this peice of code is working for one file but not for multiple files.
Can some one please tell me the reason???

for i in `ls -1 | egrep ''SOM.*` ; do
filename=$(ls -1 $i)
filename=$(print $filename)
if [[ $filename = *'.pat' ]]
then
print "Skipping file $i since it already has a .patextension\n"
else
print "Testing file $i"
last_line=$(tail -1 $i)
last_line=$(print $last_line)
if [[ $last_line = 'FOOTER'* ]]
then
print "Proper end of file detected"
print "Appending $i with .pat extension\n"
mv $i $i.pat
else
print "Proper end of file NOT detected - aborting load....\n"
fi
fi
done

Its appending .pat when only one file is there in the directory,but its failing for other files...
Reply With Quote
Forum Sponsor
  #2  
Old 01-23-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Quote:
Originally Posted by somanath Patrud View Post
Hi , this peice of code is working for one file but not for multiple files.
Can some one please tell me the reason???

for i in `ls -1 | egrep ''SOM.*` ; do
filename=$(ls -1 $i)
filename=$(print $filename
)
if [[ $filename = *'.pat' ]]
then
print "Skipping file $i since it already has a .patextension\n"
else
print "Testing file $i"
last_line=$(tail -1 $i)
last_line=$(print $last_line)
if [[ $last_line = 'FOOTER'* ]]
then
print "Proper end of file detected"
print "Appending $i with .pat extension\n"
mv $i $i.pat
else
print "Proper end of file NOT detected - aborting load....\n"
fi
fi
done

Its appending .pat when only one file is there in the directory,but its failing for other files...
Sorry, i couldn't figure out.Please tell us what is the problem that you are attempting to solve.

Thanks
Nagarajan G
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0