File reading problem via shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File reading problem via shell script
# 1  
Old 10-24-2008
File reading problem via shell script

Hi,

Data file named parameter contains :

DB=y
Alter_def.sql
Create_abc.sql

SQL=y
database.sql
my_data.sql

To read this file I use

var_sql=$(awk -F= '$1 == "SQL" { print $2 }' parameter.txt)
if [ $var_sql = "y" -o $var_sql = "Y" ]
then
sql_f_name=`grep "\.sql" parameter.txt`
echo $sql_f_name
fi

So this code returns all the file name. But I want only
database.sql
my_data.sql

these two file. Can any one suggesst me how can I get the desired result
without changing the search string(`grep "\.sql" parameter.txt`).
# 2  
Old 10-24-2008
All you need is:
(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk '/SQL=[Yy]/&&sub(/ *[^ \n]*\n/,"")' RS= parameter.txt

# 3  
Old 10-24-2008
Thanks radoulov....it's working fine
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script reading file slow

I have shell program as below #!/bin/sh echo ======= LogManageri start ========== #This directory is getting the raw data from remote server Raw_data=/opt/ftplogs # This directory is ready for process the data Processing_dir=/opt/processing_dir # This directory is prcoessed files and... (4 Replies)
Discussion started by: Chenchireddy
4 Replies

2. Shell Programming and Scripting

Reading a csv file using shell script

Hello All, I have a csv file that looks like below ProdId_A,3.3.3,some text,some/text,sometext_1.2.3 ProdId_B,3.3.3,some text,some/text,sometext_1.2.3 ProdId_C,3.3.3,some text,some/text,sometext_1.2.3 ProdId_A,6.6.6,some text,some/text,sometext_9.9.9 I will get ProdId from... (5 Replies)
Discussion started by: anand.shah
5 Replies

3. Shell Programming and Scripting

Reading arguments for a shell script from file

I have a shell script that takes 2 arguments. I will have to execute this script multiple times with different values for the arguments. for example, ./shscript env1 value1 ./shscript env1 value2 ./shscript env2 value3 ./shscript env3 value4 ./shscript env1 value5 ./shscript env3... (24 Replies)
Discussion started by: goddevil
24 Replies

4. Shell Programming and Scripting

Error while reading from a file in shell script

Hi All, I'm writing a script to read a file line by line and then perform awk function on it. I am getting an error . My file has one name in it "James". I'm expecting my o/p to be youareJamesbond James ./users.sh: line 7: =: command not found #script to read file line by line #adding... (5 Replies)
Discussion started by: Irishboy24
5 Replies

5. Shell Programming and Scripting

Reading a property file through shell script???

Hi! i need a script that can read a property file. i.e., A script to read a "property" from property file. Read the property value and based on value of property, decide whether to start the some dataload activity or not. Its urngent. Can anyone help me out???:( (7 Replies)
Discussion started by: sukhdip
7 Replies

6. Shell Programming and Scripting

Shell script - paralllel reading problem

I have a shell script which has awk utlilty,also,in it. This a single script that many other jobs (informatica) using. Each job ll generate a log file. This script will read the particular log file and need to give output. The log file is act as input file for the script. So , a single script used... (2 Replies)
Discussion started by: Gopal_Engg
2 Replies

7. Shell Programming and Scripting

file reading through shell script

For reading a file through shell script I am using yhe code : while read line do echo $line done<data.txt It reads all the line of that file data.txt. Content of data.txt looks like: code=y sql=y total no of sql files=4 a.sql b.sql c.sql d.sql cpp=n c=y total no of c files=1 (4 Replies)
Discussion started by: Dip
4 Replies

8. Shell Programming and Scripting

Reading data from a file through shell script

There is one Text file data.txt. Data within this file looks like: a.sql b.sql c.sql d.sql ..... ..... want to write a shell script which will access these values within a loop, access one value at a time and store into a variable. can anyone plz help me. (2 Replies)
Discussion started by: Dip
2 Replies

9. Shell Programming and Scripting

Shell Script -- problem reading backslash(\)!!

Hello! I am writing a program that reads a bunch of arguments from the command line,then read information from a file(passed as one of the arguments) and do some computation. The problem I am facing is when a backslash(\) is present as one of the arguments, suppose $ myprog \ abc xyz,the backslash... (2 Replies)
Discussion started by: rossi143
2 Replies

10. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question