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
# 1  
Old 04-30-2015
Need help Filtering Data from an API

Hi Everyone,

I need help on figuring out a way to filter some data that I get back from an API. Im able to get all the data that Im looking for but I would like to know a way for me to filter it better. The data that Im getting back is basically 2 rows of data as seen here.
Row 1 Row 2
Code:
ID|999MOB001|Last Contact>8 d 5 h
ID|999test13|Last Contact>2 h 0 m
ID|testipad1|Last Contact>42 m 7 s

As you can see in Row 2 I get back data that is showing the last time it was contacted.

What Im looking to get done is to get back only lines that have a specific data value that is greater than say 2 d(ays). Below is a copy of my script that Im running. So any help in what I can change to get back only the data that is older than 2 days would be helpful. From what I have been looking at I might have to use perl against my output.txt file to help sort but I wanted to see if there was a way to get this done with out using perl.

Code:
curl https:// blah blah.com/api > test.csv

sed -i '/"/d' test.csv

awk -F "\"*,\"*" '{print "ID|" $3 "|Last Contact>" $21}' test.csv > output.txt

Thanks in advance

Last edited by vgersh99; 05-01-2015 at 10:14 AM.. Reason: fixed code tags
# 2  
Old 05-01-2015
The following awk command will do that:
Code:
awk -F ">" '/Last Contact>.* d/ { if ($2 >= 2) print }' test.csv

That is, consider only lines measured in days - this scheme will fail if you encounter abbreviated month or years in your date format.
# 3  
Old 05-01-2015
Awesome thanks that worked!

Yes its only listing days and hours
# 4  
Old 05-02-2015
Did you consider simplifying and accelerating your code snippet like
Code:
curl https:// blah blah.com/api | awk -F ">" '/\"/ {next} /Last Contact>.* d/ { if ($2 >= 2) print }' > output.txt

?
# 5  
Old 05-20-2015
Thanks I tired that as well it works as well!!!

Now I have a new problem how would I set the sort to show any number of days like if I wanted to show data that was 14 D or older? Also the another issue that Im running into is that Im not showing any days that are the number 10. There are some in the file but they do not show up when I pull data that is greater than or equal to 2 days.

Code:
M105POD071,CCQML69HFMJF,53 d 2 h,6476BABC3B68,
633MOB43,DMPNRXUQG5VJ,9 d 13 h,908D6C582E1E,
103MOB14,DQTNP2HEG5VJ,17 d 21 h,2C1F23014C4A,
M153POD071,CCQLX7QUF4K1,177 d 12 h,F82793A56130,

My current code with the changes that I needed to make. But how would I edit this to pull greater than or equal to 14 d from $3???
Code:
awk -F, '/,* d/ { if ($3 >= 2 && $3 <=100) print }' test.csv

# 6  
Old 05-20-2015
Code:
awk -F'[, ]' '$3>=14 && $3<=100' test.csv

# 7  
Old 05-20-2015
Quote:
Originally Posted by vgersh99
Code:
awk -F'[, ]' '$3>=14 && $3<=100' test.csv

Thank you this is helpful but still not 100% what I need.

This brings back data that has h(hours) and m(inutes) I need to get data that is only for x-number of d(ays) and this is also stopping at 100 I need it to go past 100 to like 999 d(ays)

Code:
403mob16,DMPNPTV2G5VJ,19 h 11 m,2C1F2305E136,
999MOB001,DMRNL7EHG5VT,27 d 5 h,24A0741E65B8,
621MOB93,DMPNRPB4G5VJ,35 m 7 s,908D6C1B2D06,
M059POD071,C3TJ74NQDNQW,100 d 16 h,BC677843C4C7,

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