URGENT: Script/Function needed to read text property files in block wise


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting URGENT: Script/Function needed to read text property files in block wise
# 1  
Old 03-04-2008
URGENT: Script/Function needed to read text property files in block wise

Hi,

Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example:

Heading Name Descripton

Block Block1 Value1 Description
Property Name Value
Property Name Value
Property Name Value
Property Name Value
Property Name Value
Property Name Value
Property Name Value


Block Block2 Value2 Description
Property Name Value
Property Name Value
Property Name Value
Property Name Value
Property Name Value
Property Name Value
Property Name Value


As per the above example, my requirement is similar to this. I want to read entire bock including its name, values and process them, along with them I want to read their Property Names/Values and create under that Block.

The main requirement is, no other block's Property's should be mingled/interfered with other Block's Properties.

Any help is greatly appreciated.
# 2  
Old 03-04-2008
Show what you have come up with so far
# 3  
Old 03-04-2008
Is there any separator between 2 blocks? Or do you have something special to identify the beginning of a block? If I knew it began by "Block", say, I would write in sh something like

function block () {
local l
local b=0

read line
while [ "$line" ]; do
case "$line" in
Block*) b=$((b+1))
echo "beginning of block $b"
l=1 ;;
*) echo "line $l of block $b"
l=$((l+1))
esac
read line
done
}

Should work in ksh too.
# 4  
Old 03-04-2008
URGENT: Script/Function needed to read text property files in block wise

Hi,

Thanks for the reply. But in your script function, where do we refer to the text file from where we are reading the input. Can you explain in little bit more please.
# 5  
Old 03-04-2008
The function reads from stdin. Assuming you saved my code in a /tmp/script file, and that you wish to read a file nammed foo.txt you need to source /tmp/script, and then pipe foo.txt to the function. Namely:

source /tmp/script
block < foo.txt

or: cat foo.txt | block

BTW, my function is not ksh compatible, but bash compatible. But could properly read a file like this:

Block b1
hello line1
world line2
Block b2
hi line3
again line4
end line5
# 6  
Old 05-05-2009
Read properties file value

Hi, I have fileds like
uname="test"
pwd="ujeua"

in host.properties file.

I want to read these values in a sh file.

for i in `ls ${directory}/chk.properties
do

------how to get values here--------------

done

Thanks
# 7  
Old 05-10-2009
Reading property files from a script

Even I had a similar requirement.
Have got a way to read the properties with below command

. cfg/props.properties

but am getting the below error for every blank line

: command not found: line 8:
: command not found: line 10:
: command not found: line 12:

Can any one help me removing the blank spaces before reading the properties file? Or is there any better way to read property files?

Thanks in advance,
Surendra


Quote:
Originally Posted by KiranKumarKarre
Hi, I have fileds like
uname="test"
pwd="ujeua"

in host.properties file.

I want to read these values in a sh file.

for i in `ls ${directory}/chk.properties
do

------how to get values here--------------

done

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read files by Server Creation date wise?

Hi All, I would have many files in the server with xyz*.dat -- Static file name Physical files: xyz1.dat - 01PM xyz2.dat - 02PM xyz3.dat - 03PM In present version we are using for f in $file_name do fname=`ls $f | grep -v ^'\|'$ | sed s/' '/'\\ '/g` .... sqlldr... (4 Replies)
Discussion started by: Dharv
4 Replies

2. Shell Programming and Scripting

Script help needed(lookup 2 text files)

Hi, iam new to unix scripting need a help. The scenario is i have 2 text files. a.txt has colA colB colC colD JKU1270A JKU1042A 9 1 JKU1270A JKU1042B 9 1 JKU1270A JKU1042C 9 1 JKU1270B JKU1107B 9 1 JKU1270B JKU1107C 9 1... (1 Reply)
Discussion started by: tech_frk
1 Replies

3. Shell Programming and Scripting

how to read two text files in the same shell script

Folks i have written two scripts that do reading of csv files , i am currently fetching the all part of the line in to variables and braking the line into several variables. I am doing the same thing in an another shell script, i want to integrate both the scripts in to a single one where i can... (2 Replies)
Discussion started by: venu
2 Replies

4. Shell Programming and Scripting

Report a missing property and property value mis match script.

Hi All, I have 2 properties files - one is a master templete and other one is a node specific properties file, I need to comapre these 2 properties files and make sure the node Specific properties file contains all the properties in the master temple properties file else report the missing... (5 Replies)
Discussion started by: jayka
5 Replies

5. Shell Programming and Scripting

Combine Multiple text or csv files column-wise

Hi All I am trying to combine columns from multiple text files into a single file using paste command but the record length being unequal in the different files the data is running over to the closest empty cell on the left. Please see below. What can i do to resolve this ? File 1 File... (15 Replies)
Discussion started by: venky_ibm
15 Replies

6. Shell Programming and Scripting

Shell Script Needed to Read a text from a list files

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (4 Replies)
Discussion started by: kashriram
4 Replies

7. Shell Programming and Scripting

Need to zip the files date wise --urgent Help needed

Hi all, this is my first post, i need to write a script to zip the files with datewise below are the log files. -rw------- 1 root sso 85316156 May 24 22:11 core_test_smservaz_104_104_1243217459_8896 -rw------- 1 root sso 90413304 May 25 22:12 core_test_smservaz_104_104_1243303895_20912... (4 Replies)
Discussion started by: lcschandu
4 Replies

8. UNIX for Advanced & Expert Users

How to compare two text files in column wise?

Hi All, I have two txt files like this File1: no name ---------- 12 aaaa 23 bbbb 55 cccc File2 dname dno ------------ civil 33 mech 55 arch 66 Now i want to compare col1 from File and col2 from File2, if its match i want fetch all columns from... (3 Replies)
Discussion started by: psiva_arul
3 Replies

9. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

10. UNIX for Dummies Questions & Answers

Urgent answer needed, please: help with a text editor

I'm sorry if this has been posted before, but I'm in a big hurry and I need a pretty quick answer: I have to make a project for school which consists of many BASH scripts. At school we have Sun Sparcs. During the laboratory hours I used to open the text editor (in the graphics interface), edit the... (4 Replies)
Discussion started by: MtFR
4 Replies
Login or Register to Ask a Question