![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| reading from stdin in a shell script | mmesford | Shell Programming and Scripting | 4 | 07-04-2009 03:28 AM |
| Reading data from a file through shell script | Dip | Shell Programming and Scripting | 2 | 10-20-2008 01:51 PM |
| reading XML datas via Shell Script | freepal | Shell Programming and Scripting | 1 | 02-08-2008 11:52 AM |
| Reading a table in a shell script | luiscarvalheiro | Shell Programming and Scripting | 13 | 08-10-2006 07:16 PM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 05:25 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 a.c ..... ....... Now, if sql=y and total no of sql files > 0 then want to fetch the only sql file names via shell script. the script should fetch a.sql b.sql c.sql d.sql |
|
||||
|
Code:
> cat temp.txt
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
a.c
> cat get_sql.ksh
echo "Enter the string.. \c";
read str
option=`grep "$str=" temp.txt|awk -F"=" '{print $2}'`
if [ "$option" = "y" ]
then
nooffile=`grep "$str files=" temp.txt|awk -F"=" '{print $2}'`
if [ "$nooffile" > "0" ]
then
echo "FILES...."
grep "\.${str}" temp.txt
fi
fi
[OUTPUT] Enter the string.. sql FILES.... a.sql b.sql c.sql d.sql Enter the string.. c FILES.... a.c [/OUTPUT] |
|
||||
|
call below script with whatever parameter you like, such as 'sql' or 'c' will print the result accordingly Code:
nawk -v f="$1" -F"=" '{
if ($1==f && $2="y")
f1=1
if(f1==1 && $2>0)
f2=1
file=sprintf(".%s",f)
if(f2==1 && index($0,file)!=0)
print $0
}' filename
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|