finding number in exact column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding number in exact column
# 1  
Old 01-19-2012
finding number in exact column

Dear all,

I want to find a number in exact column but I don't know how to do it.

Here is the thing, data is shown below, and I want to find 416 in the first column and print it out, how should I deal with it? Thank you very much!

Code:
ab33 50S01S 958 279.068999 67.251013 -150.172544 67.250000 -150.166667 1.000000 
p721 10D07S 670 360.080693 45.002876 -110.002049 45.000000 -110.000000 2.000000 
p682 10G08S 730 720.072461 42.503302 -110.907523 42.500000 -110.900000 1.000000 
yac 45L01S 1073 918.272412 60.548704 -145.749858 60.550000 -145.733333 1.000000 
p716 10E03S 384 929.291764 44.718258 -110.511512 44.716667 -110.500000 7.000000 
p434 21B01S 791 958.767801 47.740203 -121.075609 47.733333 -121.083333 1.000000 
385 21E05S 733 1008.105624 44.434844 -121.945818 44.433333 -121.933333 1.000000 
703 22C13S 1012 1129.240237 46.145300 -122.196290 46.150000 -122.183333 7.000000 
ab39 45R01S 961 1239.222796 66.559346 -145.212631 66.566667 -145.233333 1.000000 
416 21B62S 928 1522.856762 47.039940 -121.596930 47.050000 -121.583333 1.000000 
lid 19K07S 652 1587.198692 39.314277 -119.884287 39.300000 -119.883333 3.000000 
p680 11E31S 609 1681.722583 44.598357 -111.098749 44.583333 -111.100000 1.000000 
p351 14F12S 490 1765.354757 43.874415 -114.719163 43.866667 -114.700000 1.000000 
p024 15B09S 803 2367.486094 47.562202 -115.842434 47.550000 -115.816667 1.000000 
p700 22C10S 748 2586.572452 46.178130 -122.217349 46.183333 -122.250000 12.000000 
p708 10F30S 1082 2590.800887 43.786390 -110.933579 43.766667 -110.916667 4.000000 
p692 22C12S 777 3142.166348 46.224494 -122.184192 46.250000 -122.166667 5.000000 
p698 22C13S 1012 3144.877395 46.173466 -122.160611 46.150000 -122.183333 7.000000 
p713 10E07S 816 3155.919570 44.389671 -110.543734 44.366667 -110.566667 2.000000 
p690 22C13S 1012 3373.068445 46.179989 -122.189869 46.150000 -122.183333 7.000000 
p699 22C10S 748 3681.617055 46.189783 -122.203226 46.183333 -122.250000 12.000000 
ikr 50O01S 1072 3758.505227 63.552727 -150.922211 63.533333 -150.983333 3.000000 
791 21D08S 651 3765.896876 45.344531 -121.672684 45.316667 -121.700000 1.000000 
735 23G09S 558 3770.273135 42.691610 -123.230999 42.716667 -123.200000 10.000000 
rn86 11H60S 1098 3930.588800 41.864856 -111.502514 41.900000 -111.500000 2.000000 
tah 11H60S 1098 3931.080070 41.864854 -111.502574 41.900000 -111.500000 2.000000 
p697 22C13S 1012 4218.251803 46.187642 -122.176609 46.150000 -122.183333 7.000000 
p693 22C10S 748 4747.385902 46.210322 -122.202348 46.183333 -122.250000 12.000000 
p705 22C10S 748 4820.487371 46.173000 -122.310630 46.183333 -122.250000 12.000000 
798 10F30S 1082 4822.886202 43.796028 -110.960579 43.766667 -110.916667 4.000000

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 01-19-2012 at 05:22 PM..
# 2  
Old 01-19-2012
Code:
awk '$1 == 416' file

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-19-2012
Thanks! Another quesiton

Quote:
Originally Posted by Corona688
Code:
awk '$1 == 416' file

Thanks for you response.

I have another question about it, that is ,when I get the number(416), how can I print out the number in the 3rd column of this row(928)?

Thanks!

---------- Post updated at 01:40 PM ---------- Previous update was at 01:31 PM ----------

Quote:
Originally Posted by Corona688
Code:
awk '$1 == 416' file

Do I need a loop? Use foreach?

Thanks
# 4  
Old 01-19-2012
Quote:
Originally Posted by handsonzhao
Do I need a loop? Use foreach?
No, awk checks the expression against every line in the file, sort of like how grep does. But awk has comparisons and variables and all the things you need to actually write a program, where grep can only match and print lines.

Quote:
I have another question about it, that is ,when I get the number(416), how can I print out the number in the 3rd column of this row(928)?

Thanks!
Code:
awk '$1 == 416 { print $3 }' file

# 5  
Old 01-19-2012
Thanks, it works when searching for 416, but it fails when searching for 'ab33' for example.
# 6  
Old 01-20-2012
Code:
awk '$1 == "ab33" { print $3 }' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Regex to match Exact port number (netstat command)

Hi All, We have this regex:\\*.*?(.600).*?.(LISTEN|ESTABLISHED) OS = Solaris 10 The purpose of this regex is to match the ports in output of "netstat -an" and report if any ports between 6000-6009 are getting used. The only problem is if I have something like this (sample output as... (6 Replies)
Discussion started by: sk2code
6 Replies

2. Shell Programming and Scripting

To get the exact column data

Hi All, I have a input file contains below data crw-r--r-- 1 oracle dba 34, 10 Nov 26 11:50 asm_aue2cu_arch01 crw-r--r-- 1 oracle dba 34, 9 Dec 8 11:00 asm_aue2cu_data01 crw-r--r-- 1 oracle dba 34, 16 Nov 25 20:25 asm_bdeccu_arch01 crw-r--r-- ... (2 Replies)
Discussion started by: kannan84
2 Replies

3. Shell Programming and Scripting

how to finding the exact pattern

I have a output like below: A1 B2 C1 D3 A12 B4 A14 I am trying to find A1 by using grep grep -i "A1" But I got (4 Replies)
Discussion started by: anupdas
4 Replies

4. Red Hat

finding exact version of Red Hat Linux

Hi, I would like to know how to find out exact version of linux on the basis of kernel level, uname -a 2.6.18-238.1.1.el5 from above command how to find out exact version of redhat linux? it is showing that version of redhat is 5.0 but it comes under which update like 1,2,3,4,5,6 ... (1 Reply)
Discussion started by: manoj.solaris
1 Replies

5. Shell Programming and Scripting

Question on awk for finding the column number using a match word

Hi Guys, Please help me out in my situation of writing a shell script Exampl:I have a output like asnapply 1 2 3 apply_server=1 apply_schema=ASN asnapply 1 2 3 apply_server=2 apply_schema=ASN Now i need output like asnacmd applysever=1 applyschema=ASN stop asnacmd applysever=2... (16 Replies)
Discussion started by: mallak
16 Replies

6. Shell Programming and Scripting

Finding the line with the exact same number

Hello All, What i am doing is , i tail a file from certain chatacter and then cat -n to get the line numbers.I search for a particular string and gets it line number. What i am interested in is the next line immediately after the pattern i search. But grep gives me result for all line... (5 Replies)
Discussion started by: kailash19
5 Replies

7. Shell Programming and Scripting

Finding exact match string

Hi All, I'm writing unix script, it should find exact matching in search string. Looks simple but when i started i'm stuck to find the exact match character string. The unix script reads the records from DB Table. The table will have values something likes these Feed : A Feed File name :... (3 Replies)
Discussion started by: luckybalaji
3 Replies

8. Shell Programming and Scripting

awk to print exact field number

Hello there. I want some help with awk I have this script that reads a file from awk and you can insert from keyboard any list from the fields that exist so to be printed on monitor echo "give a choice" read -a ans array=${ans} awk -F: -v k="$array" '{ ... (4 Replies)
Discussion started by: covis
4 Replies

9. Shell Programming and Scripting

AWK seach for exact word in certain column

Can anyone help me how I will extract all lines in a file where the word "worker" or "co-worker" in 2nd column exist. There are also word in 2nd column like "workers" or "worker2" but I don't want to display those lines. Appreciate any help in advance! Thank you! (5 Replies)
Discussion started by: Orbix
5 Replies

10. UNIX for Dummies Questions & Answers

finding exact characters

I want to grep from a file an exact character match. I tried grep -c "$a $b" $file where a=6 and b=2 the problem is that I get: 6 2 and 6 20 I just need a count of the occurrence. I'm using the Bourne shell. I've also tried grep -c '$a $b' $file; not sure how to do this - any suggestions? (3 Replies)
Discussion started by: jrdnoland1
3 Replies
Login or Register to Ask a Question