Grep awk sed display value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep awk sed display value
# 1  
Old 02-06-2013
Grep awk sed display value

Hello all,

I wget a file and i tried to display some value :

Code:
content=$(wget IP:9005/GlobalStatistics -q -O -) 
echo onlineusers $content > /home/active_session_log

#cat active_session_log 

{"ActiveSessionCount":0,"ActiveGameCount":0,"QueueMatchMakingPlayerCount":0}

My goal is write log file with ActiveSessionCount and the value

Exemple :
Code:
#cat ActiveSessionCount.log 
ActiveSessionCount 0

Any idea?

Last edited by joeyg; 02-06-2013 at 01:21 PM.. Reason: Please wrap commands and data with CodeTags
# 2  
Old 02-06-2013
Code:
awk -F'[:|,]' '/ActiveSessionCount/{ gsub(/\"|\{/,x,$1); print $1, $2 } ' active_session_log

# 3  
Old 02-06-2013
Code:
awk -F'[":,]' '{print $2,$4}' active_session_log > ActiveSessionCount.log

@bipinajith
I think you do some wrong in your field separator
You can do this -F'[:,]' or this -F':|,'
This -F'[:|,]' gives : | , as separators
This User Gave Thanks to Jotne For This Post:
# 4  
Old 02-06-2013
ok great :P
Code:
awk -F'[:,]' '/ActiveGameCount/{ gsub(/\"|\{/,x,$1); print $1, $2 } ' active_session_log
ActiveSessionCount 0

and now if i would like grap the other value ?

Last edited by radoulov; 02-06-2013 at 03:23 PM..
# 5  
Old 02-06-2013
How would you like to output? to different files?
And please use code tags
# 6  
Old 02-06-2013
Yes to different files !
# 7  
Old 02-06-2013
Code:
awk -F'[":,]' '{print $6,$8}' active_session_log > ActiveGameCount.log
awk -F'[":,}]' '{print $10,$12}' active_session_log > QueueMatchMakingPlayerCount.log

---------- Post updated at 20:20 ---------- Previous update was at 20:09 ----------

All in one go
Code:
awk -F'[":,}]' '{print $2,$4 > $2".log"; print $6,$8 > $6".log" ;print $10,$12 > $10".log"}' active_session_log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep/awk/sed help

got a file as y.txt 1 abc,def,ghj 2 defj,abc.kdm,ijk 3 lmn,cbk,mno 4 tmp,tmop,abc,pkl 5 pri,chk,cbk,lmo 6 def,cbk.pro,abc.kdm i want to search in the above file the key word like abc looking for two outcomes by passing the parameter value as abc into function and the two outocmes are... (6 Replies)
Discussion started by: silgun
6 Replies

2. Shell Programming and Scripting

syslog grep/awk/sed display

What i am trying to do is pull all the "fail" and "error" from the HP-UX syslog except if it includes "sshd" or "ftpd" and IF the next line says "above message repeats NN time" display the next line. Got some of it working with someones help with sed but Im more familiare with awk. Trying... (4 Replies)
Discussion started by: Ikon
4 Replies

3. Shell Programming and Scripting

Display output as columns using grep/awk/sed

I have several files with say something like cat sparrow I can grep for "cat" and "sparrow" and usually the output is one below the other cat sparrow How can I view these as columns say Pets Birds cat sparrow Would be great if this can be on command line using awk or... (1 Reply)
Discussion started by: gubbu
1 Replies

4. UNIX for Dummies Questions & Answers

grep/awk/sed?

Thread1 { x = 2 y = 10485 } Thread2 { x = 16 y = 1048 } Thread3 { x = 1 y = 1049 } Thread4 { x = 4 y = 1047 z = 500 } Suppose the above is a piece of code. I need to automate and verify that the value of x under Thread1's 2. There are several... (3 Replies)
Discussion started by: foxtron
3 Replies

5. Shell Programming and Scripting

help using sed/awk/grep

thanks for your reply. but i'm not quite sure what your code is doing. i may be using it wrong but i'm not getting what i'm supposed to get. could you please elaborate? thanks again, (6 Replies)
Discussion started by: kratos.
6 Replies

6. UNIX for Dummies Questions & Answers

How could i get this by sed or grep or awk ????

------------------------------------------------------------------ Ex of Warning messgae,(Many similar lines occure for Both Test and Test1) -WARNING:Below Field not implemented in file File name: /home/test/ new/file1, msg buffer is: :Test:000948 ... (1 Reply)
Discussion started by: prsam
1 Replies

7. UNIX for Dummies Questions & Answers

Grep Sed or Awk?

I have two .txt files one called good.txt and the other one is called bad.txt. Both contain email addresses in the following format: john@john.com bob@bob.com sarah@sarah.com Basically, I want to scrub good.txt against bad.txt and save the resulting output in scrubbed.txt meaning that if... (2 Replies)
Discussion started by: holyearth
2 Replies

8. UNIX for Dummies Questions & Answers

Awk, Sed and Grep

Hello. I am an older newbie trying to learn Unix. I have a task to perform and it entails counting lines of code. Currently, I am pointing to the directory where the files are contained and performing a 'find' on the file extensions (cpp, c, html, java, etc.) and piping that info with a 'wc -l'.... (2 Replies)
Discussion started by: mastachef
2 Replies

9. Shell Programming and Scripting

Sed | Awk | Grep

Can someone help me in understanding when to use SED, AWK and GREP (3 Replies)
Discussion started by: kn.naresh
3 Replies

10. Shell Programming and Scripting

need help!!!awk,grep,sed

hi all by using cat /etc/passwd I've got these output. ajh1ect:x:839:501:Anthony:/home/ajh1ect:/bin/bash mjb1ect:x:840:501:Michael:/home/mjb1ect:/bin/bash mv3ect:x:841:501:Marian:/home/mv3ect:/bin/bash now I want to see just the user ID and group ID. so what is the code will be with... (2 Replies)
Discussion started by: nokia1100
2 Replies
Login or Register to Ask a Question