![]() |
|
|
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 |
| count the max by awk | halola85 | Shell Programming and Scripting | 9 | 12-01-2008 07:44 AM |
| replaying a record count with another record count | er_zeeshan05 | Shell Programming and Scripting | 2 | 10-30-2008 12:14 AM |
| Sorting using count, grep and count | sukhpal_78 | UNIX for Dummies Questions & Answers | 2 | 06-27-2008 01:13 AM |
| Display the count of files | wayne1411 | Shell Programming and Scripting | 4 | 01-09-2008 10:09 PM |
| How to count the record count in an EBCDIC file. | oracle8 | UNIX for Dummies Questions & Answers | 1 | 07-26-2006 08:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
A bit trikier now.
From the result of a mysql query I actually need to: 1) save the number of rows into one variable ($count) 2) save first field of last line into another variable ($id) Can you assign variables inside a awk script? The query: Code:
santiago:~$ mysql -e 'SELECT id, name FROM terminal' +----+------------------+ | id | name | +----+------------------+ | 3 | John Smith | | 18 | Alan Parker | | 41 | Bob Johnson | +----+------------------+ I could do that by running the query two times but that's what I'd like to avoid. Code:
santiago:~$ count=$(mysql -e 'SELECT id, name FROM terminal' | wc -l) santiago:~$ id=$(mysql -e 'SELECT id, name FROM terminal' | tail -1 | cut -f1) Santiago Last edited by chebarbudo; 02-27-2009 at 09:50 AM.. |
|
||||
|
Assuming that the output of mysql command would be :
Code:
id name 3 John Smith 18 Alan Parker 41 Bob Johnson Code:
result=$(mysql -e 'SELECT id, name FROM terminal' | awk '{count=NR;id=$1} END{print count" "id}')
count=$(echo $result | awk '{print $1}')
id=$(echo $result | awk '{print $2}')
|
![]() |
| Bookmarks |
| Tags |
| echo, tee, wc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|