Multiple files read error in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple files read error in Shell
# 1  
Old 09-27-2010
Java Multiple files read error in Shell

Hi All,
there is a script that reads multiple files in a directory starting with CTG_TMPxx where xx is an integer number.
i have a problem in readin the last file. For example, if there are 10 files in that directory, 9 files are read and processed. but the 10th file, its saying as cannot read the file from the directory.

Here is the snippet .(Assuming that there are 3 files starting with CTG_TMPxx in the directory)

Code:
val=`ls -l CTG_TMP* | wc -l`
v=0
while [[ $val -ne 0 ]]; do
while read line ;do
echo "$dt $line" >> file$v.log
done < CTG_TMP$val.log | sed 's/ //g'
((val = $val - 1))
((v = $v + 1))
done

the output is

Code:
$ test.ksh
A file or directory in the path name does not exist.
test.ksh[38]: CTG_TMP 3.log: 0403-016 Cannot find or open the file.
CTG_TMP3.log
CTG_TMP2.log
CTG_TMP1.log

can i know the exact cause of this error?
y am i not able to read the last file?

Last edited by Scott; 09-27-2010 at 02:50 PM.. Reason: Please use code tags
# 2  
Old 09-27-2010
how about:

Code:
for file in CTG_TMP* ; do

  sed -e "s/^/$dt /" $file > $file.log

done

'course, if you run it twice, you'll get "log.log's" but you could probably figure out how to fix that. Hint: different output directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to read multiple files...

I have 7 text files of varying sizes for each month of System Maintenance done during the 2013 calendar year (Jan. 134 jobs, Feb. 84 jobs, Apr. 594 jobs, May 158 jobs, July 69 jobs, Aug. 1 job, Oct. 102 jobs) and I have another text file which contains everything from those 7 files. Each of the... (8 Replies)
Discussion started by: CyberOptiq
8 Replies

2. UNIX for Dummies Questions & Answers

awk - how to read multiple files

Hi, is there a ways to read multiple files in a single awk command? For example: awk -f awk_script file1 file2 file3 I've google it, most of them suggest using FNR. But I don't understand how it works. It will be a great help if someone able to explain it in simple term with some example. (4 Replies)
Discussion started by: KCApple
4 Replies

3. Shell Programming and Scripting

read the lines of multiple files

I am trying to create a script which will read 2 files and use the lines of file 1 for each line on file 2. here's my sample code cat $SBox | while read line do cat $Date | while read line do $SCRIPTEXE <line from first file> $2 <line from 2nd file> ... (12 Replies)
Discussion started by: khestoi
12 Replies

4. Shell Programming and Scripting

Read multiple text file in shell sccript

I need help. I need to read all current and incoming text file in the directory and change it's content to 0. The following code change the content of the text file to 0, however, the code always assumes that the files are ALREADY present. Is there any way where I can change the file1_.txt,... (3 Replies)
Discussion started by: jasperux
3 Replies

5. UNIX for Advanced & Expert Users

Use awk to read multiple files twice

Hi folks I have a situation where I am trying to use awk to compute mean and standard deviation for a variable that spans across multiple files. The layout of each file is same and arranged in 3 columns and uses comma as a delimiter. File1 layout: col1,col2,col3 0,0-1,0.2345... (13 Replies)
Discussion started by: scandy
13 Replies

6. Shell Programming and Scripting

How to Read Multiple files in a Shell Script

Hi, Can any one tell me if i can read two files in a shell script... My actual requirement is to read the 1st text file and parse it to get the file code and use this file code to retrieve data from database and print the fetched data in the 2nd text file (I have parsed it and printed the... (2 Replies)
Discussion started by: funonnet
2 Replies

7. Shell Programming and Scripting

need shell or Perl script to read multiple input

I need shell 0r Perl script to read multiple input and do something and come out example: echo “ enter the host names separated by space “ read servers foreach @servers { do do something done} Here host names like host1 host2 host3 . . . . . . . so on Please help me... (8 Replies)
Discussion started by: sreedhargouda
8 Replies

8. Shell Programming and Scripting

Shell script to read multiple log files

Hi all, I have to generate some report from shell script .We have stacktrace log file which generate hourly basis. So now my q is that how this shell script will read all stacktrace log file for particlular day and parse accordingly desire output. Any help or suggestion as i am newbie with... (1 Reply)
Discussion started by: esungoe
1 Replies

9. Shell Programming and Scripting

How to read from multiple files

Hi All, I have list of multiple files with 7 fields all together. Those are being split to exact lines of 20000 each. xaa xab : : : xhx Please advise me how to read from those files and in fact I need to invoke and sql update statement for each inputs values.. Regards, (5 Replies)
Discussion started by: cedrichiu
5 Replies

10. Shell Programming and Scripting

Perl program to read from multiple files

Hi, I need to generate a test data file by reading inputs from multiple files. A sample pseudo code for this program to read from three files and write to a output file would be like: open(OUTPUTFILE, "data"); open(INFILE1, "data1"); open(INFILE2, "data2"); open(INFILE3, "data3"); ... (1 Reply)
Discussion started by: jyotipg
1 Replies
Login or Register to Ask a Question