Sponsored Content
Top Forums Shell Programming and Scripting Read section of file and take decision Post 302513783 by dips_ag on Friday 15th of April 2011 02:45:51 AM
Old 04-15-2011
Hi Pravin,

Actually from the XML file I am able to extract values for below variables:
Code:
$src_database=Oracle
$src_datatype=number
$tgt_datatype=double

Quote:
Note: I cannot paste XML file content as it's client info.
What I want now is to check if number = double is fine?
This translation I can read from config file only. Hope I'm clear now. Sorry for the confusion my initial post created.

-dips

---------- Post updated 2011-04-15 at 12:15 PM ---------- Previous update was 2011-04-14 at 02:23 PM ----------

Hi,

I'm able to read a section of file by changing the format of the file a little

Changed config file:
Code:
 
$cat temp.cfg
landing_dir=XXXX
scripts_dir=XXXX
....
 
<Oracle>
number|double;integer  
blob|binary
varchar2|string
varchar|string
number(p,s)|decimal
timestamp|date/time
<Oracle>
 
<Sybase>
bigint|bigint
datetime|date/time
money|decimal
smallint|small integer
....
<Sybase>

To read only "Oracle" section from the file (searched forum)
Code:
 
awk '/\<Oracle\>/{p=0}p;/\<Oracle\>/{p=1}' temp.cfg

In my script I'll have variables holding source & target datatypes as below:
Code:
$src_datatype=number
$tgt_datatype=double

Scenario 1
Now as $src_datatype variable is "number" then I want to read only
Code:
 
number|double;integer

this line from the temp.cfg

and check whether $tgt_datatype is either of them i.e. "double" or "interger"?

Scenario 2
If $src_datatype variable is "number(p,s)" then I want to read only
Code:
 
number(p,s)|decimal

this line from temp.cfg

and check whether $tgt_datatype is "decimal" ?

I tried
Code:
 
awk '/\<Oracle\>/{p=0}p;/\<Oracle\>/{p=1}' temp.cfg | grep -w "$src_datatype"

but it selects two lines
Code:
 
number|double;integer
number(p,s)|decimal

Please advice on how to proceed further. Thanks for your time.

-dips
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

help find a section line of a file

hi, I have a 20 line file. I need a command which will brinf back a specific line based upon the line number I enter. e.g. the file looks like this and is called file1 jim is a man john is a woman james is a man wendy is a woman lesley is a woman i want a command that will... (4 Replies)
Discussion started by: sureshy
4 Replies

2. Shell Programming and Scripting

How to read a specific section and modify within

Hi, I am n00b to shell scripting and I am learning Ksh, sed and awk. I have a requirement and need your help. 1) How to read a specific section of a file. I have a file and I want to read the contents between say "Page Number:1" to "End of Page 1" 2) Within the section of the file that was... (2 Replies)
Discussion started by: kn.naresh
2 Replies

3. Shell Programming and Scripting

Using Sed to duplicate a section of a file....

hello all, I have a file like this: section 1 blah1 blah2 section 2 blah1 blah2 section 3 blah1 blah2 and I want to use sed to duplicate section 2, like this: section 1 blah1 blah2 section 2 blah1 blah2 section 2 blah1 (2 Replies)
Discussion started by: nick26
2 Replies

4. Shell Programming and Scripting

cutting a section of a big file

Hi, I have a text file 10giga size. Opening the file with vi takes forever ... Im intersting only with the 100 first records. Is there way to copy those 100 lines to new file (with no need to open the file)? Thanks (6 Replies)
Discussion started by: yoavbe
6 Replies

5. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

6. Shell Programming and Scripting

Delete a section of a file if...

i have a file as below that has n section : 2006 0101 1236 49.3 L 37.902 48.482 0.0 Teh 5 0.2 2.7LTeh 1 GAP=238 E Iranian Seismological Center, Institute of Geophysics, University of Tehran 6 ... (5 Replies)
Discussion started by: oreka18
5 Replies

7. Shell Programming and Scripting

Fetch a section from a file

Hi, I have a file like... $cat file1 +++++++++++++++++++ client1 +++++++++++++++++++++++++++++ col1 col2 col3 ------ ----- ----- (0 rows affected) ========================================================= +++++++++++++++++++ client1 +++++++++++++++++++++++++++++ col1 col2 col3... (6 Replies)
Discussion started by: sam05121988
6 Replies

8. Shell Programming and Scripting

awk to lookup section of file in a range of another file

In the below, I am trying to lookup $1 and $2 from file1, in a range search using $1 $2 $3 of file2. If the search key from file1 is found in file2, then the word low is printed in the last field of that line in the updated file1. Only the last section of file1 needs to be searched, but I am not... (6 Replies)
Discussion started by: cmccabe
6 Replies

9. Shell Programming and Scripting

How to segregate a section from big file?

Hello, I need to know all IP range (ip_prefix), associated with us-west-2 region only from this link - https://ip-ranges.amazonaws.com/ip-ranges.json (it can be opened in wordpad for better visibility) Please suggest, how would I do it. If vi, awk or sed is needed, I have downloaded it on my... (7 Replies)
Discussion started by: solaris_1977
7 Replies

10. Shell Programming and Scripting

How to change file section into each line?

Hi Gurus, I have below file which has different sections, need to move the sections to beginning of the each record. original file aaa bbb ccc ddd eee fff output file. aaa bbb ccc ddd eee fff (6 Replies)
Discussion started by: green_k
6 Replies
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy