Sponsored Content
Top Forums Shell Programming and Scripting bash assign mysql query single field to variable Post 302420460 by unclecameron on Tuesday 11th of May 2010 04:58:47 PM
Old 05-11-2010
bash assign mysql query single field to variable

I'm running a bash script query and assigning the output to a variable like this:
Code:
exists=`mysql -u $USER_NAME --password=$PASSWORD -D "somedb" \
           -e "SELECT * FROM somedb.sometable WHERE field1 ='$a' \
           AND field2 ='$b' LIMIT 0 , 30";`

which returns something like:
Code:
echo $exists

id field1 field2 field3 field4 field5

if field1 = $a and field2 = $b. I want to assign only one field from that output to a variable so
Code:
c=field3

I was using awk, but if field 3 is more than one word then awk thinks that's 2 fields and screws up my variable.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assign bash command to variable

Hi I am trying to write a function that needs to be able to assign the last run shell command to a variable. The actual command string itself not the exit code of the command. I am using the bash command recall ability to do this as follows: alias pb='ps | grep ash' ... (3 Replies)
Discussion started by: Moxy
3 Replies

2. Shell Programming and Scripting

Passing a variable from shell script to mysql query?

I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish... . $X='grep foo blah.log' then 'mysql command SELECT foo FROM bar WHERE ' . $X or something like that. ... (2 Replies)
Discussion started by: kero
2 Replies

3. Shell Programming and Scripting

Perl:Read single value from text file and assign to variable

Hello All, A part of my very basic perl code requires me to read a single value from a text file. The file output is the following: Reading image ... done IMAGEREGION=0x0x0-256x162x256 VOXELDIMENSION=0.9375000000x1.2000000477x0.9375000000 VOXELNUMBER=10527001... (7 Replies)
Discussion started by: ncl
7 Replies

4. Shell Programming and Scripting

Assign field value in a .csv file to a variable using ksh

Hi, I'm new to the scripting world... I want to know that how can I assign the the field value(that has multiple lines) of a .csv file to a variable??? Model of my .csv file : 1 Poppy 5 2 red 6 3 black 5 4 white 8 and so on,the list... (4 Replies)
Discussion started by: srim
4 Replies

5. Shell Programming and Scripting

Using a shell script variable in a mysql query using 'LIKE'

Hello. I am writing a simple script that reads a text file and removes records from a mysql database. The items in the text file are of the format: firstname.middle.lastXXX, where XXX is a 3 digit number. The table has an email field that will match the firstname.middle.last. So, I thought I... (1 Reply)
Discussion started by: bricoleur
1 Replies

6. Programming

mysql query multiple records for one field

Hello Group, What I have is a database with about a dozen fields and one being "City". What I would like to do is to have a custom query on a single field for multiple items (cities) but I don't know how to do this. I know this is probably kids play for most of you but I am lost. What I have... (4 Replies)
Discussion started by: vestport
4 Replies

7. Shell Programming and Scripting

Storing the value of a single query to a Variable - What am i doing wrong?

I tried the below : #!/bin/ksh testvar=$( sqlplus $user/$pass << EOF set pagesize 0 feedback off verify off heading off echo off; whenever sqlerror exit 1 SELECT 1+1 FROM DUAl; COMMIT; EXIT; EOF) echo "testvar="$testvar The output that I am getting is : > sh example.sh... (3 Replies)
Discussion started by: SriRamKrish
3 Replies

8. Shell Programming and Scripting

Conditional bash/mysql query help

I think(hope) I've got a simple one - I just need to send an email if a mysql query returns any results (ideally - it will never match). Currently I just pipe the mysql query output to the mail program, but of course that emails regardless of the output( and I check this every 10 minutes from... (5 Replies)
Discussion started by: jcass78
5 Replies

9. Shell Programming and Scripting

How to Assign the Output of an SQL Query to a Variable?

Hi iam new to shell scripting how to declare variables as redshift query and I have to compare two counts by using if condition . ex:count=select count(*) from prd; select count(*) from prd; select count(*) from tag; can any one help me . Please use CODE tags when displaying... (1 Reply)
Discussion started by: sam526
1 Replies

10. UNIX for Beginners Questions & Answers

Variable definition inside mysql query

Hello, I am running ubuntu16.04. By means of @Rudic's help, I have below command. What I need to do is to replace video_id by value of video_id in which WHERE clause is matched: {print "INSERT INTO video_series_files (id, video_id, file_type, protocol, \ url, languages, quality, accessed... (12 Replies)
Discussion started by: baris35
12 Replies
MooseX::Emulate::Class::Accessor::Fast(3pm)		User Contributed Perl Documentation	       MooseX::Emulate::Class::Accessor::Fast(3pm)

NAME
MooseX::Emulate::Class::Accessor::Fast - Emulate Class::Accessor::Fast behavior using Moose attributes SYNOPSYS
package MyClass; use Moose; with 'MooseX::Emulate::Class::Accessor::Fast'; #fields with readers and writers __PACKAGE__->mk_accessors(qw/field1 field2/); #fields with readers only __PACKAGE__->mk_ro_accessors(qw/field3 field4/); #fields with writers only __PACKAGE__->mk_wo_accessors(qw/field5 field6/); DESCRIPTION
This module attempts to emulate the behavior of Class::Accessor::Fast as accurately as possible using the Moose attribute system. The public API of "Class::Accessor::Fast" is wholly supported, but the private methods are not. If you are only using the public methods (as you should) migration should be a matter of switching your "use base" line to a "with" line. While I have attempted to emulate the behavior of Class::Accessor::Fast as closely as possible bugs may still be lurking in edge-cases. BEHAVIOR
Simple documentation is provided here for your convenience, but for more thorough documentation please see Class::Accessor::Fast and Class::Accessor. A note about introspection Please note that, at this time, the "is" flag attribute is not being set. To determine the "reader" and "writer" methods using introspection in later versions of Class::MOP ( > 0.38) please use the "get_read_method" and "get_write_method" methods in Class::MOP::Attribute. Example # with Class::MOP <= 0.38 my $attr = $self->meta->find_attribute_by_name($field_name); my $reader_method = $attr->reader || $attr->accessor; my $writer_method = $attr->writer || $attr->accessor; # with Class::MOP > 0.38 my $attr = $self->meta->find_attribute_by_name($field_name); my $reader_method = $attr->get_read_method; my $writer_method = $attr->get_write_method; METHODS
BUILD $self %args Change the default Moose class building to emulate the behavior of C::A::F and store arguments in the instance hashref. mk_accessors @field_names Create read-write accessors. An attribute named $field_name will be created. The name of the c<reader> and "writer" methods will be determined by the return value of "accessor_name_for" and "mutator_name_for", which by default return the name passed unchanged. If the accessor and mutator names are equal the "accessor" attribute will be passes to Moose, otherwise the "reader" and "writer" attributes will be passed. Please see Class::MOP::Attribute for more information. mk_ro_accessors @field_names Create read-only accessors. mk_ro_accessors @field_names Create write-only accessors. follow_best_practices Preface readers with 'get_' and writers with 'set_'. See original Class::Accessor documentation for more information. mutator_name_for accessor_name_for See original Class::Accessor documentation for more information. set See original Class::Accessor documentation for more information. get See original Class::Accessor documentation for more information. meta See Moose::Meta::Class. SEE ALSO
Moose, Moose::Meta::Attribute, Class::Accessor, Class::Accessor::Fast, Class::MOP::Attribute, MooseX::Adopt::Class::Accessor::Fast AUTHORS
Guillermo Roditi (groditi) <groditi@cpan.org> With contributions from: Tomas Doran (t0m) <bobtfish@bobtfish.net> Florian Ragwitz (rafl) <rafl@debian.org> LICENSE
You may distribute this code under the same terms as Perl itself. perl v5.10.0 2009-09-15 MooseX::Emulate::Class::Accessor::Fast(3pm)
All times are GMT -4. The time now is 08:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy