bash query.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash query.
# 1  
Old 10-25-2012
Debian bash query.

I have a $file which will be used as an input file for the script, pasting ie.

Code:
16              VDBDN084_K_TPVV016     SDBDN081 5:3:2   t  4313  273 4313  69077   3689  69077   2.0  2.1  16.0  13.5    5
 16              VDBDN084_K_TPVV016     SDBDN081 4:3:3   t  4313  273 4313  69890   3679  69890   1.3  1.6  16.2  13.5    6
 16              VDBDN084_K_TPVV016     SDBDN081 5:3:2   t  4097  182 4097  60396   2213  60396  2.0  2.1  14.7  12.2    5
 16              VDBDN084_K_TPVV016     SDBDN081 4:3:3   t  4097  182 4097  59092   2184  59092  1.4  1.8  14.4  12.0    9
 15              VDBDN084_K_TPVV015     SDBDN081 5:3:2   t  1082  626 1082  81584   7242  81584  5.6  3.9  75.4  11.6    0
 15              VDBDN084_K_TPVV015     SDBDN081 4:3:3   t  1081  626 1081  82663   7261  82663  4.3  3.8  76.4  11.6    7
 15              VDBDN084_K_TPVV015     SDBDN081 5:3:2   t  1002  634 1082 106008   9423 106008   5.7  3.9 105.8  14.9    2

initially I was counting duplicates on bases of second coulum and was using "sort $file |awk '{ print $2}'| uniq -c | sort -k1nr" in my script; but now there is a requirement and I have to count duplicate on basis of 2nd column and 4 column and also want to print the output of 2nd and 4th column.

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 10-25-2012 at 04:33 AM..
# 2  
Old 10-25-2012
Please use code tags for data input and code.

you can print in awk.


Code:
awk '{ print $2,$4}' $file | sort | uniq -c | sort -k1nr

From your above code it looks like you want unique values with respect to $2 and $4.

use this..
It will give you unique values..

Code:
awk '!X[$2,$4]++' $file


Last edited by pamu; 10-25-2012 at 04:31 AM..
# 3  
Old 10-25-2012
To also limit the output to two columns:
Code:
awk '{$0=$2 OFS $4}!A[$0]++' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Query on using command "sed" for replacing text in bash shell

Re: Query on using command "SED" for replacing text in bash shell While using the command "sed" for find and replace, I wanted to know how one could find a constant and replace it with a variable inside the quotation syntax of sed? I wanted to replace constant 3 with variable name... (3 Replies)
Discussion started by: achandra81
3 Replies

2. 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

3. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

4. UNIX for Dummies Questions & Answers

bash script & sql query

Hi Guys, I would like with this script "DATA=`ora123 su -c 'echo "SET HEADING OFF;\n SET FEED OFF;\n select USER NAME, ACCOUNT_STATUS from dba_users;\n exit" | sqlplus / as sysdba -s /' ` echo $DATA >> $DAT" make a sql query, but the statement "select USER NAME, ACCOUNT_STATUS from... (6 Replies)
Discussion started by: ixibits
6 Replies

5. Shell Programming and Scripting

bash assign mysql query single field to variable

I'm running a bash script query and assigning the output to a variable like this: 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: echo... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Linux

Query on Bash Shell

Hi, I have a query regarding how the commands are getting displayed to the terminal on the bash shell. Lets say i am typing a command "ls" on the command prompt. Does the bash reads the command until the new line is entered and then processes it or is it like first the bash reads the character... (2 Replies)
Discussion started by: roshantraj30
2 Replies

8. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. UNIX for Dummies Questions & Answers

Query regarding alias and setting bash as a default script

Hi All, I am setting bash as my working shell in my .profile file. So I have written a line : bash as the list line in my .profile I want to use alias as follows: alias me='who am i' When i log in, as expeced I enter the bash shell but alias doesn't work. Is it because the alias is defined... (1 Reply)
Discussion started by: VENC22
1 Replies
Login or Register to Ask a Question