Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Ksh Storing Multiple Files and reading each line in each file. Post 302183282 by developncode on Tuesday 8th of April 2008 04:41:39 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.10 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 08:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy