Ksh Storing Multiple Files and reading each line in each file.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Ksh Storing Multiple Files and reading each line in each file.
# 1  
Old 04-08-2008
Question Ksh Storing Multiple Files and reading each line in each file.

How would I go about storing multiple file paths in a directory that begin like: 20080402*
and run a loop that reads each line of each file thats in a given directory. So far this is what I have:


#!/bin/ksh
echo "ENTER Reprint Date (YYYYMMDD): "
read ReprintDate
echo ""
ReprintDateCount=$(echo ${ReprintDate} | wc -m)
if [[ $ReprintDateCount -ne 9 ]]
then
echo "INVALID Reprint Date! ${ReprintDateCount}"
echo "RE-ENTER Reprint Date (YYYYMMDD): "
read ReprintDate
fi
echo "ENTER SITE Code Selection (ALL, A, T, M, K, L, P, and O): "
read SiteCode
echo ""
if [[ $SiteCode != "ALL" || $SiteCode != "all" || $SiteCode != "A" || $SiteCode != "a" || $SiteCode != "T" || $SiteCode != "t" || $SiteCode != "M" || $SiteCode != "m" || $SiteCode != "K" || $SiteCode != "k" || $SiteCode != "L" || $SiteCode != "l" || $SiteCode != "P" || $SiteCode != "p" || $SiteCode != "O" || $SiteCode != "o" ]]
then
echo "INVALID SITE Code Selection!"
echo "RE-ENTER SITE Code Selection (ALL , A, T, M, K, L, P, and O): "
read SiteCode
echo ""
fi
filename=~/${ReprintDate}220032*
echo "Reprint Request File: "$filename
echo ""
{ while read myline
do
if [[ ${myline} != H* && ${myline} != T* ]]
then
if [[ $myline = D* ]]
then
zipcode=$(echo ${myline} | sed 's/^[ \t]*//;s/[ \t]*$//')
zipcode=${zipcode#${zipcode% *}}
zipcount=$(echo ${zipcode} | wc -m)
state=${myline%$zipcode*}
state=$(echo ${state} | sed 's/^[ \t]*//;s/[ \t]*$//')
state=${state#${state% *}}
statecount=$(echo ${state} | wc -m)
city=${myline%$state*}
city=$(echo ${city} | sed 's/[ \t]*$//')
city=${city#${city% *}}
citycount=$(echo ${city} | wc -m)

if [[ $zipcode -lt 1 ]] && [[ $zipcode -gt 99999 ]] || [[ $zipcount -ne 6 ]]
then
echo ${myline}
echo "ZIPCODE WARNING! -> ${zipcode}"
fi
if [[ $statecount -ne 3 ]]
then
echo ${myline}
echo "STATE WARNING! -> ${state}"
fi
if [[ $citycount -lt 4 ]]
then
echo ${myline}
echo "CITY WARNING! -> ${city}"
fi
fi
fi
done } < $filename
# 2  
Old 04-08-2008
I want the script to read each line of each file in a directory that begins with: 20080402*
and I want it to print output for each file..My first thought was to use an ls command and store the results but I am not sure...I am open to all suggestions..pls help
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

2. Shell Programming and Scripting

Help with storing the output of multiple sql queries to a file

Hi All, I have a file queries.txt as follows : SELECT COLUMN1 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN1 FROM SCDEMA2.TABLE2; SELECT COLUMN2 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN2 FROM SCDEMA2.TABLE2; SELECT COLUMN3 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN3 FROM SCDEMA2.TABLE2; SELECT... (2 Replies)
Discussion started by: SriRamKrish
2 Replies

3. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

I have a environment property file which contains: Input file: value1 = url1 value2 = url2 value3 = url3 and so on. I need to search all *.xml files under directory for value1 and replace it with url1. Same thing I have to do for all values mentioned in input file. I need script in unix bash... (7 Replies)
Discussion started by: Shamkamde
7 Replies

4. Shell Programming and Scripting

Storing multiple file paths in a variable

I am working on a script for Mac OS X that, among many other things, gets a list of all the installed Applications. I am pulling the list from the system_profiler command and formatting it using grep and awk. The problem is that I want to be able to use each result individually later in the script.... (3 Replies)
Discussion started by: cranfordio
3 Replies

5. Programming

Reading Scientific notation from file and storing in array

Hi, I am trying to read a set of numbers that are in scientific notation into a file so I can do some math on them, but when I display the array contents the numbers aren't the same as the numbers in the file. Could someone explain why? Thanks. int main() { double fArray; ... (3 Replies)
Discussion started by: Filter500
3 Replies

6. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

7. Shell Programming and Scripting

Reading from a file and storing it in a variable

Hi folks, I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it. My file is 1.txt and its contents are VERSION=5.6 UPDATE=4 I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
Discussion started by: scriptfriend
6 Replies

8. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

Hi, I have a folder which contains multiple config.xml files and one input file, Please see the below format. Config Files format looks like :- Code: <application name="SAMPLE-ARCHIVE"> <NVPairs name="Global Variables"> <NameValuePair> ... (0 Replies)
Discussion started by: haiksuresh
0 Replies

9. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

10. Shell Programming and Scripting

KSH: Reading a file line by line into multiple arrays

Hi - I have a file that contains data in this format:- #comment value1 value2 value3 #comment value4 value5 value6 value7 #comment value8 value9 I need to read value1, value2 and value3 into one array, value4 value5 value6 and value7 into another array and value8 and value9 into a 3rd... (2 Replies)
Discussion started by: sniper57
2 Replies
Login or Register to Ask a Question