- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: need info on access of mysql in shell script.....
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2007 07:23 AM
тАО06-19-2007 07:23 AM
need info on access of mysql in shell script...
var1=`mysql <
now i want to access the second column(class) first row.
But whn i echo $var1. it gives all the values together
[note:there are many rows]
now how do i access the first row, thn the second,.....
Pls do write a script or give me an example.Its urgent.
thnks in advance
- Tags:
- mysql
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2007 09:26 AM
тАО06-19-2007 09:26 AM
Re: need info on access of mysql in shell script...
If various fields are separated through space then you could use awk. Can you paste the output of var1 then I could write and send it to you.
Padma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2007 10:08 AM
тАО06-19-2007 10:08 AM
Re: need info on access of mysql in shell script...
First:
If you are working in a shell, and want to get each 'name' and 'class' into a shell variable to manipulate, then you want to use 'read' and a 'while' loop. This can be done very easily, i.e.:
mysql -N -B -e 'select name, class from student' | while read NAME CLASS; do ....; done
This makes an assumption or two though.
Second:
This assumption is that 'name' or 'class' contains no spaces (not likely it seems). So this means you want to do something more like this:
----- start ------
#!/bin/sh
OFS=$IFS
IFS=|
mysql -N -e 'select name, class from student' | while read NAME CLASS
do
echo ::${NAME}::${CLASS}::
done
IFS=$OFS
-----end ------
This is messing around with the Input Field Separator, so it pays to be a little bit careful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2007 04:43 PM
тАО06-19-2007 04:43 PM
Re: need info on access of mysql in shell script...
name Hex(Status) timestamp N1 00000000000000000000000000000002 2007-06-20 10:06:00 0016e694818b
00000000000000000000000000000200 2007-06-20 10:02:18 /B1/G1/r1
00000000000000000000000000000200 2007-06-20 10:02:18
i want the fileds with 0s whch is a hexadecimal value.
i want to access all of them individually
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2007 08:43 PM
тАО06-19-2007 08:43 PM
Re: need info on access of mysql in shell script...
mysql -N -e 'select name, status, class from student' | while read NAME STATUS CLASS
Your 3 values are '$NAME', '$STATUS' and '$CLASS'. All individually accessable within the loop.
The '-N' flag, coupled with the IFS redelegation are important, as these set up the structure for the 'read'.