forked from dheera/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifference
More file actions
executable file
·30 lines (24 loc) · 806 Bytes
/
difference
File metadata and controls
executable file
·30 lines (24 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
import subprocess
import sys
if len(sys.argv) < 3:
print("Difference of 2 command outputs.")
print("Example:")
print(" difference \"ls -1 directory_a\" \"ls -1 directory_b\"")
exit()
try:
out0 = subprocess.check_output(sys.argv[1], shell=True).decode('utf-8').split('\n')
except subprocess.CalledProcessError:
print("First command returned error, aborting")
exit()
try:
out1 = subprocess.check_output(sys.argv[2], shell=True).decode('utf-8').split('\n')
except subprocess.CalledProcessError:
print("Second command returned error, aborting")
exit()
out0 = filter(lambda x:x.strip() != '', out0)
out1 = filter(lambda x:x.strip() != '', out1)
set0 = set(out0)
set1 = set(out1)
setout = set0 - set1
print('\n'.join(sorted(list(setout))))