- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Re: need info on access of mysql in shell script.....
-
- Forums
-
Blogs
- Hybrid Cloud
- Edge
- Data & AI
- Working in Tech
- AI Insights
- Alliances
- Around the Storage Block
- Behind the scenes at Labs
- Careers in Tech
- HPE Storage Tech Insiders
- Inspiring Progress
- IoT at the Edge
- My Learning Certification
- OEM Solutions
- Servers: The Right Compute
- Shifting to Software-Defined
- Telecom IQ
- Transforming IT
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Russia
- HPE Blog, UK & Ireland
- Blogs
-
Quick Links
- Community
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Contact
- Email us
- Tell us what you think
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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'.
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2019 Hewlett Packard Enterprise Development LP