Skip to content

Commit 3e1e332

Browse files
committed
Add json parsing bash script using jq
1 parent 1a69b20 commit 3e1e332

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Bash/JSON_Parse_with_jq/find_flag.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Bash/JSON_Parse_with_jq/sample.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)