The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
urgent help needed!!in copying files to /tmp at boot time,pls help! wrapster UNIX for Advanced & Expert Users 0 04-27-2008 11:00 AM
urgent-extracting block data from flat file using shell script shirish_cd Shell Programming and Scripting 4 02-06-2008 09:05 AM
script needed urgent jayaramanit Shell Programming and Scripting 2 09-11-2007 09:35 AM
Urgent Script Needed skyineyes UNIX for Dummies Questions & Answers 1 06-20-2007 05:36 AM
Urgent answer needed, please: help with a text editor MtFR UNIX for Dummies Questions & Answers 4 05-22-2004 01:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-04-2008
ysreenivas ysreenivas is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 2
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 (permalink)  
Old 03-04-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,941
Show what you have come up with so far
  #3 (permalink)  
Old 03-04-2008
xavier054 xavier054 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 11
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 (permalink)  
Old 03-04-2008
ysreenivas ysreenivas is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 2
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 (permalink)  
Old 03-04-2008
xavier054 xavier054 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 11
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 (permalink)  
Old 05-05-2009
KiranKumarKarre KiranKumarKarre is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 62
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 (permalink)  
Old 05-10-2009
suren321 suren321 is offline
Registered User
  
 

Join Date: May 2009
Posts: 1
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 View Post
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0