Need help Filtering Data from an API


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help Filtering Data from an API
# 8  
Old 05-20-2015
Code:
awk -F'[, ]' '$4=="d" && $3>=14 && $3<=100' myFile

just modify the above to modify your integer value ranges.

Last edited by vgersh99; 05-20-2015 at 02:41 PM..
# 9  
Old 05-20-2015
Fantastic that worked!!!

Any chance you can explain how that worked?

What does the $4=="d" do? Is that looking 4 placed in front of d?
# 10  
Old 05-20-2015
Quote:
Originally Posted by TheStruggle
Fantastic that worked!!!

Any chance you can explain how that worked?

What does the $4=="d" do? Is that looking 4 placed in front of d?
$4 is the forth field. The field separator is specified by -F'[, ]' . So it's either a comma or a space. Now look at your sample data Smilie
This User Gave Thanks to vgersh99 For This Post:
# 11  
Old 05-20-2015
Ahhh.....now I see it. Thanks Again!
# 12  
Old 06-26-2015
Code:
124mob7,iOS 8.3,iPad Air 2,6.3,DMPNRMTHG5VJ,1 h 4 m,908D6C582D84
M215POD2,iOS 8.3,iPod touch 5th gen,6.2,CCQPM37YFMJF,10 d 22 m,48E9F12FD989
M155POD072,iOS 8.2,iPod touch 5th gen,6.3,CCQM129ZF4K1,31 d 3 h,F827939F3D33
M115POD053,iOS 8.3,iPod touch 5th gen,6.3,CCQMCCTGFMJF,3 d 0 h,B03495D4AE6F

Code:
awk -F'[, ]' '$9=="d" && $6>=14'

Hi Guys like my name says I'm still struggling with this. The last code I had worked great but now they want more data from our devices and now I'm not able to get back my data by filtering it the same way. I made a change to the awk command to go to the 9th column which I think is correct but I have also tried it with 10 or 11 and I get different results. Any help as to why I'm now not able to get back the data that I want and sort it correctly?

I think my issue is that I have different data in column 3. Sometimes its 2 words and 1 space, 3 words and 2 spaces or 4 words and 3 spaces. Would I need a while loop or something like that? If so can you provide an example?

Thanks

Last edited by TheStruggle; 06-26-2015 at 03:03 PM..
# 13  
Old 06-26-2015
You may want to run this against your sample file:
Code:
awk -F"[, ]" '{for (i=1; i<=NF; i++) print "field", i, ": ", $i}' file

# 14  
Old 06-26-2015
Quote:
Originally Posted by RudiC
You may want to run this against your sample file:
Code:
awk -F"[, ]" '{for (i=1; i<=NF; i++) print "field", i, ": ", $i}' file

This is a nice piece of code THANKS! It showed me that I sometimes have 12 fields or 13 or 14. I would guess that this is where my problem is. This is where I now think a while loop or something might be what I need to address the variance in the column???
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read info from api website and show retrieved data

good evening, i'm still new in scripting but i'm learning every day and i'm enjoying it. so i have api website (htt p://api.nobelprize.org/v1/prize.json), i want to make a script that allows me to give it two arguments like ./test.sh 2005 physics, 2000 is for the year and physics is category... (1 Reply)
Discussion started by: kalbsghir
1 Replies

2. Shell Programming and Scripting

Filtering out the data with dates

Hi, I have some data like seen below. format : apple(hhmm mm/dd).fruit apple(2345 03/25).fruit apple(2345 05/06).fruit orange(0443 05/02).fruit orange(0345 05/05).fruit orange(2134 05/04).fruit grape(0930 04/24).fruit grape(2330 03/30).fruit I need to get the data which are... (1 Reply)
Discussion started by: jayadanabalan
1 Replies

3. Shell Programming and Scripting

Need to run an API from a script and extract fields from output of API

Hi, I need to call an API (GetUsageDetails)from inside a shell script which takes an input argument acct_nbr. The output of API will be like : <usageAccum accumId="450" accumCaptn="PM_125" inclUnits="1410.00" inclUnitsUsed="744.00" shared="true" pooled="false" prorated="false"... (1 Reply)
Discussion started by: rkrish
1 Replies

4. Shell Programming and Scripting

awk data filtering

I am trying to filter out some data with awk. If someone could help me that would be great. Below is my input file. Date: 10-JUN-12 12:00:00 B 0: 00 00 00 00 10 00 16 28 B 120: 00 00 00 39 53 32 86 29 Date: 10-JUN-12 12:00:10 B 0: 00 00 00 00 10 01 11 22 B 120: 00 00 00 29 23 32 16 29... (5 Replies)
Discussion started by: thibodc
5 Replies

5. Shell Programming and Scripting

Filtering data using AWK

Hi , i have file with delimiter as "|" and data in Double codes for all fields. how to filter data in a column like awk -F"|" '$1="asdf" {print $0}' test. ex : "asdf"|"zxcv" Thanks, Soma (1 Reply)
Discussion started by: challamsomu
1 Replies

6. Shell Programming and Scripting

help need in filtering data

Hello Gurus, Please help me out of the problem. I ve a input file as below input clock; input a; //reset all input b; //input comment output c; output d; output e; input f; //output comment I need the output as follows: \\Inputs (1 Reply)
Discussion started by: user_prady
1 Replies

7. UNIX for Dummies Questions & Answers

Filtering Data

file1 contain: (this just a small sample of data it may have thousand of lines) 1 aaa 1/01/1975 delhi 2 bbb 2/03/1977 mumbai 3 ccc 1/01/1975 mumbai 4 ddd 2/03/1977 chennai 5 aaa 1/01/1975 kolkatta 6 bbb 2/03/1977 bangalore program: nawk '{ idx= $2 SUBSEP $3 arr = (idx in arr) ?... (2 Replies)
Discussion started by: bobo
2 Replies

8. Shell Programming and Scripting

Filtering Data

Hi All, I have the below input and expected ouput. I need a code which can scan through this input file and if the number in column1 is more than 1 , it will print out the whole line, else it will output "No Re-occurrence". Can anybody help ? Input: 1 vvvvv 20 7 7 23 0 64 6 zzzzzz 11 5... (7 Replies)
Discussion started by: Raynon
7 Replies

9. UNIX for Dummies Questions & Answers

Filtering out data ...

I have following command which tells me File size in GBs which are greater than 0.01GBs recursively in a dir structure. ls -l -R | awk '{ if ($5/1073741824 >= 0.01) print $9, $5/1073741824 }' But there are some files whom I dont have enough permissions, after executing this script gives me... (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question