回答編集履歴
3
edit
answer
CHANGED
@@ -6,8 +6,10 @@
|
|
6
6
|
import subprocess
|
7
7
|
run = subprocess.getoutput
|
8
8
|
|
9
|
-
|
9
|
+
run("echo 'apple\norange\ngrape\nhoge' > test.txt")
|
10
|
-
ans = run(cmd.split())
|
11
10
|
|
11
|
+
cmd = "grep -A 100 orange test.txt"
|
12
|
+
ans = run(cmd)
|
13
|
+
|
12
14
|
print(ans)
|
13
15
|
```
|
2
edit
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
import subprocess
|
7
7
|
run = subprocess.getoutput
|
8
8
|
|
9
|
-
cmd = "grep -A 3 orange"
|
9
|
+
cmd = "grep -A 3 orange test.txt"
|
10
10
|
ans = run(cmd.split())
|
11
11
|
|
12
12
|
print(ans)
|
1
edit
answer
CHANGED
@@ -1,3 +1,13 @@
|
|
1
1
|
subprocessからgrepをコールしても達成できます。
|
2
2
|
|
3
|
-
コードの用途などによるかと。
|
3
|
+
コードの用途などによるかと。
|
4
|
+
|
5
|
+
```pythox
|
6
|
+
import subprocess
|
7
|
+
run = subprocess.getoutput
|
8
|
+
|
9
|
+
cmd = "grep -A 3 orange"
|
10
|
+
ans = run(cmd.split())
|
11
|
+
|
12
|
+
print(ans)
|
13
|
+
```
|