select data from list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting select data from list
# 1  
Old 07-19-2010
select data from list

Hi!
My data file contains a two columns list. It looks like:
1 3.789
2 6.789
3 7.890
4 8.900
5 6.789
6 1.987
7 10.987
8 2.987
9 0.987
I would like to create a new list using the awk command, just selecting data from the second column but also printing the first column.
Let say I select the data from a range from 0 to 4 and the print file would look like:
1 3.789
6 1.987
8 2.987
9 0.987
Order does not matter
Thanks for your help
# 2  
Old 07-19-2010
Hope this is not a class assignment.

This is not 100% but you should be able to figure out the fix.

Code:
awk '{ if(($2 > 0) && ($2 < 5)) { print $1" "$2}}' yourdatafile.txt

This User Gave Thanks to Ikon For This Post:
# 3  
Old 07-19-2010
It`s not a class assignment, I`m just new at awk.
Thanks
# 4  
Old 07-19-2010
Or shorter:
Code:
awk '$2 > 0 && $2 < 5' file

Without an action part between braces {...} awk prints the current record by default if the condition is true.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to select 2D data bins

I wish to use AWK to do something akin: Select all 2D data with 1<$1<2 and -7.5<$2<-6.5 But it's not working awk 'END {print ($1<=2&&$1>=1&&$2<=-6.5&&$2>=-7.5)}' bla Data: -1.06897 -8.04482 -61.469 -1.13613 -8.04482 -61.2271 -1.00182 -8.04482 -61.2081 -1.06897 -8.13518 -60.8544... (2 Replies)
Discussion started by: chrisjorg
2 Replies

2. UNIX for Dummies Questions & Answers

Select last update data based on file name

Hi All, I need to remove all files except the most update data based on date on filename Input data_AIDS_20150312.txt data_AIDS_20150311.txt data_AIDS_20150411.txt data_AIDS_20140312.txt the most updated data is data_AIDS_20150411.txt, so I'll remove other files. My expected output... (3 Replies)
Discussion started by: radius
3 Replies

3. UNIX for Dummies Questions & Answers

Using grep to select data from file

Hello all, Once again I need to call upon the masters for help. I have a file called endpoint_data. IN that file I have groups of endpoints. However all I need from the file is this.... ENDPOINT NAME = SIPWOODSBC SIG PRI FQDN/IP ADDRESS/DOMAIN NAME = 10.xxx.xxx.xxx SIG SEC... (4 Replies)
Discussion started by: jay11789
4 Replies

4. Shell Programming and Scripting

Like to select text in a From/To list

Hi I need help to configure AWK to find a string based From/To filed I have a table like this 0A00 - 0AFF Nuts 0B00 - 0BFF Bolt If I have in a program a value like "0B22" I wold like to get "Bolt" in return. List are in Hex Still try to learn AWK :) (3 Replies)
Discussion started by: Jotne
3 Replies

5. Shell Programming and Scripting

Sed for select and retrieve data

I would like to recover the data from 3 text tags. These three markers are located between the tags specific location <tag1> and </tag1> knowing that they are in many places. In File.txt: <tag2>txt2</tag2> <tag3>txt3</tag3> <tag4>txt4</tag4> .... <tag1> <tag2>txt2</tag2>... (3 Replies)
Discussion started by: Amad
3 Replies

6. Shell Programming and Scripting

Select data from a file

Hi , I want to select data from a file .the datas in a file will be in both upper and lower case. can able to select particular data using awk. file is like Ram Selva 24332 UNIXTEAM Karthi Siva 43322 UNIXTEAM In read if i enter selva as lowercase its not displaying result. (9 Replies)
Discussion started by: boopal
9 Replies

7. Programming

sockets - can you send data while waiting on select()

Hey guys, Is it possible to have a worker thread send data out a TCP connection while another thread is waiting using using select() on that same connection? If not, then what is the correct way to maintain a connection, react to incoming data, and send data over a TCP connection? Thanks... (16 Replies)
Discussion started by: scubanarc
16 Replies

8. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

9. UNIX for Dummies Questions & Answers

Awk - select from a list

Hi all, I am trying to select some columns from a file, based on the list of values. Would like to know how best I can achive this. If coulmn 1 has a value of 57 then print the ist column (This works) awk -F' ' '{if ( $1 == 57 ) {print $1}}' file.txt Now my requirement is that I have to... (14 Replies)
Discussion started by: simha77777
14 Replies

10. Shell Programming and Scripting

Displaying the data from the select query in a particular format

Hi, I have a shell script that returns 10 records for the column Name and age from a select query. Where when i store those data in retrieve_list.txt file i need to store the data in a particular format like:- $Jason$30 $Bill$23 $Roshan$25 Here is my script: 1)... (15 Replies)
Discussion started by: sachin.tendulka
15 Replies
Login or Register to Ask a Question