回答編集履歴
1
追記
answer
CHANGED
@@ -6,4 +6,36 @@
|
|
6
6
|
|
7
7
|
`1i` で、1行目に挿入、です。
|
8
8
|
|
9
|
-
(CentOS + bash で試しているので Mac + zsh で動かなかったらごめんなさい)
|
9
|
+
(CentOS + bash で試しているので Mac + zsh で動かなかったらごめんなさい)
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
[sed on OSX insert at a certain line](http://unix.stackexchange.com/questions/52131/sed-on-osx-insert-at-a-certain-line)
|
14
|
+
|
15
|
+
Mac の sed はかなり異なっているようです。。。
|
16
|
+
|
17
|
+
- i の後ろにバックスペースと改行が必要
|
18
|
+
- i で改行を挿入できない(ので x と p で代替)
|
19
|
+
|
20
|
+
```
|
21
|
+
sed -i '' -e $'1{\ni\\\nTitle\nx\np\np\nx\ni\\\nmessage : hogehoge\n}' sample.txt
|
22
|
+
```
|
23
|
+
|
24
|
+
下記と同じです。
|
25
|
+
|
26
|
+
```
|
27
|
+
sed -i '' '1{
|
28
|
+
i\
|
29
|
+
Title
|
30
|
+
x
|
31
|
+
p
|
32
|
+
p
|
33
|
+
x
|
34
|
+
i\
|
35
|
+
message : hogehoge
|
36
|
+
}
|
37
|
+
' sample.txt
|
38
|
+
```
|
39
|
+
|
40
|
+
(Mac + bash で試しているので Mac + zsh で動かなかったらごめんなさい)
|
41
|
+
|