File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ ### json parsing in bash
2
+
3
+ ` find_flag.sh ` sctipt will tell you how to use [ jq] ( https://stedolan.github.io/jq/ ) command to parse JSON file in bash with an example (` sample.json ` )
4
+
5
+ The script will run below 3 commands and find the flag from the ` sample.json ` file
6
+
7
+ ``` bash
8
+ $ cat sample.json | jq " ." | head -n 13
9
+ ```
10
+
11
+ ``` bash
12
+ $ cat sample.json | jq " .data.allPosts.edges[0:3]"
13
+ ```
14
+
15
+ ``` bash
16
+ $ cat sample.json | jq " .data.allPosts.edges" | grep -E -o ' RotteN{.*}' | grep -v ' harder'
17
+ ```
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ echo " ##########################################################"
4
+ echo " ### Let's check first few lines of the json file ..."
5
+ echo " ##########################################################"
6
+ echo " "
7
+ echo " $ cat sample.json | jq \" .\" | head -n 13"
8
+ echo " "
9
+ echo " Press any key to continue"
10
+ while [ true ] ; do
11
+ read -t 3 -n 1
12
+ if [ $? = 0 ] ; then
13
+ cat sample.json | jq " ." | head -n 13
14
+ break
15
+ else
16
+ echo " ..."
17
+ fi
18
+ done
19
+
20
+ echo " "
21
+ echo " ##########################################################"
22
+ echo " ### Now analyzing a couple of node objects under edges... "
23
+ echo " ##########################################################"
24
+ echo " "
25
+ echo " $ cat sample.json | jq \" .data.allPosts.edges[0:3]\" "
26
+ echo " "
27
+ echo " Press any key to continue"
28
+ while [ true ] ; do
29
+ read -t 3 -n 1
30
+ if [ $? = 0 ] ; then
31
+ cat sample.json | jq " .data.allPosts.edges[0:3]"
32
+ break
33
+ else
34
+ echo " ..."
35
+ fi
36
+ done
37
+
38
+ echo " "
39
+ echo " ##########################################################"
40
+ echo " ### We'll use grep to get a unique secret value..."
41
+ echo " ##########################################################"
42
+ echo " "
43
+ echo " $ cat sample.json | jq \" .data.allPosts.edges\" | grep -E -o 'RotteN{.*}' | grep -v 'harder'"
44
+ echo " "
45
+ echo " Press any key to continue"
46
+ while [ true ] ; do
47
+ read -t 3 -n 1
48
+ if [ $? = 0 ] ; then
49
+ cat sample.json | jq " .data.allPosts.edges" | grep -E -o " RotteN{.*}" | grep -v " harder"
50
+ exit
51
+ else
52
+ echo " ..."
53
+ fi
54
+ done
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments