Need help to Build logic
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Need help to Build logic




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Need help to Build logic  
pankaj_wolfhunter@yahoo.co.in


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-06 07:49 AM

Greetings,
I have a file like

my_details1
my_name
my_details1
my_address
my_details1
my_number
your_details
your_name
your_details
your_emailid
your_details
your_number
......
......
......

In the file, the first line represents the table name and the
consecutive field represents its column.
like my_details1 is the name of the table and my_name, my_address,
my_number represents its respective fields. and then the second table
starts as your_details with its respective fields.
I want to take this whole file in a loop and for a particular table i
want to put all its respective fields into a new file. as

echo SELECT my_name, my_address, my_number FROM my_details1 >
newfile.sql

I am not able to build a logic for this.

Can someone help me?

Any help would be appreciated.

TIA






[ Post a follow-up to this message ]



    Re: Need help to Build logic  
Icarus Sparry


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-06 07:49 AM

On Mon, 13 Mar 2006 22:38:30 -0800, pankaj_wolfhunter wrote:

> Greetings,
>                  I have a file like
>
> my_details1
> my_name
> my_details1
> my_address
> my_details1
> my_number
> your_details
> your_name
> your_details
> your_emailid
> your_details
> your_number
> ......
> ......
> ......
>
> In the file, the first line represents the table name and the
> consecutive field represents its column.
> like my_details1 is the name of the table and my_name, my_address,
> my_number represents its respective fields. and then the second table
> starts as your_details with its respective fields.
> I want to take this whole file in a loop and for a particular table i
> want to put all its respective fields into a new file. as
>
> echo SELECT my_name, my_address, my_number FROM my_details1 >
> newfile.sql
>
> I am not able to build a logic for this.
>
> Can someone help me?
>
> Any help would be appreciated.
>
> TIA

Untested (i.e. I just typed this in).

while read tablename
do
read cname
if [ "X$tablename" = "X$lasttable" ]
then
# This is another entry from the same table, append it
columns="$columns, $cname"
else
[ -n "$lasttable" ] &&
echo "SELECT $columns FROM $lasttable"
lasttable="$tablename"
columns="$cname"
fi
done
# output the final entry if there is one
[ -n "$lasttable" ] &&
echo "SELECT $columns FROM $lasttable"

The basic idea is to have a loop which reads in the tablename, and inside
the loop we read the column. If the table name has changed, and we have
something ready for output then we output it, otherwise we add the column
onto the list of columns we want.

Put this into a file, redirect stdin from your file, send the output to
newfile.sql






[ Post a follow-up to this message ]



    Re: Need help to Build logic  
pankaj_wolfhunter@yahoo.co.in


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-06 07:49 AM

Thanks a ton Icarus. It works. Thanks again.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:08 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register