why is it workin for 1 file , but not for multiple files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting why is it workin for 1 file , but not for multiple files?
# 1  
Old 01-23-2008
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...
# 2  
Old 01-23-2008
Quote:
Originally Posted by somanath Patrud
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output file name and file contents of multiple files to a single file

I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt. I need each line prefaced with the hostname. I am unsure how to do this. --- Post updated at... (5 Replies)
Discussion started by: Kentlee65
5 Replies

2. Shell Programming and Scripting

Bash regex evaluation not workin

I'm building a script that may received start and end date as parameters. I whant to make it as flexible as possible so I'm accepting epoch and date in a way that "date --date=" command may accept. In order to know if parameter provided is an epoc or a "date --date=" string I evaluate if the value... (2 Replies)
Discussion started by: lramirev
2 Replies

3. Shell Programming and Scripting

Copying a file to multiple other files using a text file as input

Hello, I have a file called COMPLIST as follows that contains 4 digit numbers.0002 0003 0010 0013 0015 0016 0022 0023 0024 0025 0027 0030 0031 0032 0033 0035 0038 0041 (3 Replies)
Discussion started by: sph90457
3 Replies

4. Shell Programming and Scripting

How to split file into multiple files using awk based on 1 field in the file?

Good day all I need some helps, say that I have data like below, each field separated by a tab DATE NAME ADDRESS 15/7/2012 LX a.b.c 15/7/2012 LX1 a.b.c 16/7/2012 AB a.b.c 16/7/2012 AB2 a.b.c 15/7/2012 LX2 a.b.c... (2 Replies)
Discussion started by: alexyyw
2 Replies

5. Shell Programming and Scripting

How to ftp multiple files by taking the file name from a input file.

Hi, I'm working on a script which has to copy multiple files from one server to another server. The list of files that are to be copied is present in a file say input.txt. vi input.txt abc.c welcome.c new.c welcome1.c for ftp'ing a single file say 'new.c' the following code... (2 Replies)
Discussion started by: i.srini89
2 Replies

6. Shell Programming and Scripting

Split a file into multiple files based on first two digits of file.

Hi , I do have a fixedwidth flatfile that has data for 10 different datasets each identified by the first two digits in the flatfile. 01 in the first two digit position refers to Set A 02 in the first two digit position refers to Set B and so on I want to genrate 10 different files from my... (6 Replies)
Discussion started by: okkadu
6 Replies

7. Shell Programming and Scripting

Splitting a file in to multiple files and passing each individual file to a command

I have an input file with contents like: MainFile.dat: 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 ... (4 Replies)
Discussion started by: rkrish
4 Replies

8. Shell Programming and Scripting

determine the periodfor which user is workin

write a shell script that determines the period for which a specified user is workin on the system. (3 Replies)
Discussion started by: shawz
3 Replies

9. Shell Programming and Scripting

rsh within awk is not workin

cat input.sh | awk ' { cur1=tolower($1) cur2=tolower($2) rsh $cur1 report | grep $cur2 } ' hi, Have a look at the above code, the input.txt file contains two words in each line with space as delimiter, the first word is computer name and the 2nd word is file... (2 Replies)
Discussion started by: geeko
2 Replies

10. IP Networking

recv() not workin fine.....

hi ! In my program I have a structure as shown below: struct data { int a; char *b; long c; }str; i have assigned the following values to it: strcpy(str.b,"John"); str.a=10; str.c=123435; The client is tryin to send struct data to the server using send(sock,(char *... (2 Replies)
Discussion started by: mridula
2 Replies
Login or Register to Ask a Question