Differences

This shows you the differences between two versions of the page.

Link to this comparison view

shell [2018/03/22 10:57]
dblume [Command Template]
shell [2019/01/17 21:25] (current)
dblume [jq Tips]
Line 387: Line 387:
 done done
 </code> </code>
 +Alternatively, to see the RSS use of that process alone: 
 +<code bash> 
 +while true; do sync; cat /proc/$(pidof yourprocess)/status | grep VmRSS; sleep 1; done 
 +</code>
 ====== Measuring Available Memory ====== ====== Measuring Available Memory ======
  
Line 460: Line 463:
     src/platform/main.cpp:521     src/platform/main.cpp:521
     src/Application.cpp:95     src/Application.cpp:95
 +    
 +====== Sort by Frequency ======
 +
 +I ran the following P4 command to find out who's been editing a file recently:
 +
 +   $ find . -name fname.cpp | xargs p4 filelog -s -m 10 | grep -P "^\.\.\. #" | \
 +     awk '{print $9}' | cut -d @ -f 1 | sort | uniq -c | sort -nr
 +
 +====== jq Tips ======
 +
 +jq is really handy. Here's a tip for some processing I often do:
 +
 +<file javascript fruits.txt>
 +{ "fruits":
 +  {
 +    "apple":
 +       {
 +          "name": "Apple",
 +          "price" : 2
 +       },
 +    "banana":
 +       {
 +          "name": "Banana",
 +          "price" : 3
 +       },
 +    "count": 2,
 +    "open": true
 +  }
 +}
 +</file>
 +
 +<code>
 +$ jq '.fruits|del(.count,.open)|with_entries(.value |= .price)' fruits.txt
 +{
 +  "apple": 2,
 +  "banana": 3
 +}
 +
 +# with_entries(f) is an alias for to_entries | map(x) | from_entries
 +
 +jq '.fruits|del(.count,.open)|to_entries|map(.value |= .price)|from_entries' f
 +{
 +  "apple": 2,
 +  "banana": 3
 +}
 +
 +$ jq '.fruits|del(.count,.open)|[to_entries[]|{(.key): .value.price}]|add' fruits.txt
 +{
 +  "apple": 2,
 +  "banana": 3
 +}
 +</code>
 +
 +<file javascript fruit_ip.txt>
 +{
 +  "192.168.144.52": {
 +    "ipAddress": "192.168.144.52",
 +    "attributes": {
 +      "model": "apple",
 +      "name": "David's apple"
 +    }
 +  },
 +  "192.168.144.40": {
 +    "ipAddress": "192.168.144.40",
 +    "attributes": {
 +      "model": "banana",
 +      "name": "David's banana"
 +    }
 +  }
 +}
 +</file>
 +
 +<code>
 +$ jq '[to_entries[]|{"key":.value.attributes.name,"value":.key}]|from_entries' fruit_ip.txt
 +{
 +  "David's apple": "192.168.144.52",
 +  "David's banana": "192.168.144.40"
 +}
 +
 +$ jq '[.[]|{(.attributes.name):.ipAddress}]|add' fruit_ip.txt
 +{
 +  "David's apple": "192.168.144.52",
 +  "David's banana": "192.168.144.40"
 +}
 +
 +$ jq -r "to_entries|map(\"\(.value.attributes.name) = \(.key)\")|.[]" fruit_ip.txt
 +David's apple = 192.168.144.52
 +David's banana = 192.168.144.40
 +</code>
 +
 +
 ====== Additional Keywords ====== ====== Additional Keywords ======
  
 Linux, Unix, *nix Linux, Unix, *nix
shell.1521741432.txt.gz · Last modified: 2018/03/22 10:57 by dblume
 
Recent changes RSS feed Driven by DokuWiki