-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand_line_options.html
More file actions
640 lines (352 loc) · 29.1 KB
/
command_line_options.html
File metadata and controls
640 lines (352 loc) · 29.1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<!DOCTYPE HTML>
<html lang="ko" >
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-161001174-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-161001174-2');
</script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Command-line options | Introduction</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
<meta name="generator" content="GitBook 2.6.7">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="./styles/website.css">
<link rel="next" href="./debugging.html" />
<link rel="prev" href="./execute.html" />
</head>
<body>
<div class="book"
data-level="9"
data-chapter-title="Command-line options"
data-filepath="command_line_options.md"
data-basepath="."
data-innerlanguage="">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="0" data-path="index.html">
<a href="./index.html">
<i class="fa fa-check"></i>
Introduction
</a>
</li>
<li class="chapter " data-level="1" data-path="bug_reports.html">
<a href="./bug_reports.html">
<i class="fa fa-check"></i>
<b>1.</b>
Bug reports
</a>
</li>
<li class="chapter " data-level="2" data-path="basics.html">
<a href="./basics.html">
<i class="fa fa-check"></i>
<b>2.</b>
Basics
</a>
<ul class="articles">
<li class="chapter " data-level="2.1" data-path="regex.html">
<a href="./regex.html">
<i class="fa fa-check"></i>
<b>2.1.</b>
Regex
</a>
</li>
<li class="chapter " data-level="2.2" data-path="escape_sequences.html">
<a href="./escape_sequences.html">
<i class="fa fa-check"></i>
<b>2.2.</b>
Escape sequences
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="3" data-path="addresses.html">
<a href="./addresses.html">
<i class="fa fa-check"></i>
<b>3.</b>
Addresses
</a>
</li>
<li class="chapter " data-level="4" data-path="and_or_not.html">
<a href="./and_or_not.html">
<i class="fa fa-check"></i>
<b>4.</b>
AND, OR, NOT
</a>
</li>
<li class="chapter " data-level="5" data-path="commands.html">
<a href="./commands.html">
<i class="fa fa-check"></i>
<b>5.</b>
Commands
</a>
<ul class="articles">
<li class="chapter " data-level="5.1" data-path="print.html">
<a href="./print.html">
<i class="fa fa-check"></i>
<b>5.1.</b>
print
</a>
</li>
<li class="chapter " data-level="5.2" data-path="delete.html">
<a href="./delete.html">
<i class="fa fa-check"></i>
<b>5.2.</b>
delete
</a>
</li>
<li class="chapter " data-level="5.3" data-path="quit.html">
<a href="./quit.html">
<i class="fa fa-check"></i>
<b>5.3.</b>
quit
</a>
</li>
<li class="chapter " data-level="5.4" data-path="substitute.html">
<a href="./substitute.html">
<i class="fa fa-check"></i>
<b>5.4.</b>
substitute
</a>
</li>
<li class="chapter " data-level="5.5" data-path="next.html">
<a href="./next.html">
<i class="fa fa-check"></i>
<b>5.5.</b>
next
</a>
</li>
<li class="chapter " data-level="5.6" data-path="move.html">
<a href="./move.html">
<i class="fa fa-check"></i>
<b>5.6.</b>
move between spaces
</a>
</li>
<li class="chapter " data-level="5.7" data-path="insert_append_change.html">
<a href="./insert_append_change.html">
<i class="fa fa-check"></i>
<b>5.7.</b>
insert, append, change
</a>
</li>
<li class="chapter " data-level="5.8" data-path="read_write.html">
<a href="./read_write.html">
<i class="fa fa-check"></i>
<b>5.8.</b>
read, write
</a>
</li>
<li class="chapter " data-level="5.9" data-path="etc.html">
<a href="./etc.html">
<i class="fa fa-check"></i>
<b>5.9.</b>
etc
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="6" data-path="branch.html">
<a href="./branch.html">
<i class="fa fa-check"></i>
<b>6.</b>
Branch
</a>
</li>
<li class="chapter " data-level="7" data-path="multiple_lines.html">
<a href="./multiple_lines.html">
<i class="fa fa-check"></i>
<b>7.</b>
Multiple lines
</a>
</li>
<li class="chapter " data-level="8" data-path="execute.html">
<a href="./execute.html">
<i class="fa fa-check"></i>
<b>8.</b>
Execute
</a>
</li>
<li class="chapter active" data-level="9" data-path="command_line_options.html">
<a href="./command_line_options.html">
<i class="fa fa-check"></i>
<b>9.</b>
Command-line options
</a>
</li>
<li class="chapter " data-level="10" data-path="debugging.html">
<a href="./debugging.html">
<i class="fa fa-check"></i>
<b>10.</b>
Debugging
</a>
</li>
<li class="chapter " data-level="11" data-path="tips.html">
<a href="./tips.html">
<i class="fa fa-check"></i>
<b>11.</b>
Tips
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Actions Left -->
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="./" >Introduction</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<h1 id="commandline-options">Command-line options</h1>
<p>sed 는 명령 라인에서 스크립트 스트링이나 <code>-e</code>, <code>-f</code> 옵션을 사용하지 않으면 인수로 사용된 파일명 중에서
첫번째 파일을 명령 스크립트 파일로 그리고 나머지 파일들을 데이터 파일로 취급합니다.
아무런 데이터 파일도 인수로 주지 않을 경우는 stdin 에서 입력을 받습니다.</p>
<h4 id="n-quiet-silent">-n, --quiet, --silent</h4>
<p>sed 의 디폴트 출력 모드인 자동 출력 모드를 disable 합니다.</p>
<h4 id="e-script-expressionscript">-e script, --expression=script</h4>
<p>스크립트가 길어질 경우 가독성을 위해 <code>-e</code> 옵션을 이용해 분리해 작성할 수 있습니다.
shell 에서 명령문을 작성할 때 파이프로 sed 명령이 중복되어 연결되어 있다면
<code>-e</code> 옵션을 이용해 한번의 명령 실행으로 바꿀 수 있습니다.
또한 insert, append, execute 같은 명령을 사용할 때 필요한 옵션입니다.</p>
<p><code>-e</code> 옵션이 사용되면 처음 식에도 모두 <code>-e</code> 옵션을 붙여야 합니다.</p>
<h4 id="f-scriptfile-filescriptfile">-f script-file, --file=script-file</h4>
<p>실행할 스크립트 파일을 지정합니다.</p>
<h4 id="e-r-regexpextended">-E, -r, --regexp-extended</h4>
<p>Extended Regular Expressions 을 사용합니다.</p>
<h4 id="u-unbuffered">-u, --unbuffered</h4>
<p>입, 출력에 버퍼를 사용하지 않습니다.
<code>tail -f</code> 같은 명령과 함께 사용할때 필요한 옵션 입니다.</p>
<h4 id="s-separate">-s, --separate</h4>
<p>sed 는 기본적으로 인수로 전달되는 데이터 파일들을 모두 합쳐서 하나의 스트림으로 취급합니다.
그러므로 10 개의 데이터 파일이 인수로 전달되어도 <code>1p</code> 명령은 한번만 출력됩니다.
하지만 <code>-s</code> 옵션을 사용하면 각각 분리된 스트림으로 취급하여 <code>1p</code> 명령은 10 번 출력됩니다.</p>
<h4 id="z-nulldata">-z, --null-data</h4>
<p>라인 구분자로 newline 대신에 NUL 문자를 사용합니다.
특정 명령에서 라인 구분자를 NUL 문자로 하여 출력할 경우에 사용되는데
이외에도 파일 전체를 한번에 pattern space 로 읽어들이는 용도로 사용할 수 있습니다.
이때 M flag 를 이용한 multi-line 모드는 사용할 수 없습니다.</p>
<h4 id="l-n-linelengthn">-l <em>N</em>, --line-length=<em>N</em></h4>
<p><code>l</code> 명령은 pattern space 의 내용을 분석할 때 사용하는 명령인데요.
기본적으로 escape sequence 형태로 출력하므로 개행을 하지 않습니다.
이 옵션을 이용하면 line-wrap length 를 지정할 수 있습니다.
default 는 70 이고 length 값을 0 으로 설정하면 no wrap 입니다.</p>
<h4 id="isuffix-inplacesuffix">-i[<em>SUFFIX</em>], --in-place[<em>=SUFFIX</em>]</h4>
<p>이 옵션은 sed 를 이용해 파일 내용을 직접 수정할 때 사용합니다.<br>특히 디렉토리를 recursive 하게 검색해서 매칭 되는 파일들을 모두 수정할 때 편리합니다. </p>
<p>처리되는 순서는 다음과 같습니다.</p>
<ol>
<li><p>먼저 임시 파일을 만들어서 처리중에 결과를 저장합니다.</p>
</li>
<li><p>처리가 완료되면 임시 파일을 원본 파일명으로 변경하고 원본 파일은 삭제합니다.</p>
</li>
<li><p>이때 SUFFIX 값이 주어졌으면 원본 파일을 삭제하지 않고 SUFFIX 를 붙여서 보관합니다.</p>
</li>
</ol>
<p>그러므로 용량이 큰 파일일 경우 저장공간이 처리하고자 하는 파일의 2배가 필요하고
처리가 완료된 파일은 새로운 inode 를 갖는 파일이 됩니다.</p>
<pre><code class="lang-bash">$ ls
data1 data2 data3
<span class="hljs-comment"># SUFFIX 는 -i 옵션에 공백 없이 붙인다.</span>
$ sed -i.orig <span class="hljs-string">'s/XXX/YYY/'</span> *
$ ls
data1 data1.orig data2 data2.orig data3 data3.orig
-------------------------------------------------------
<span class="hljs-comment"># ./dir 디렉토리 이하 모든 파일을 검색해서 'hello' 를 포함하고 있을 경우 foo 를 bar 로 변경</span>
$ grep -rl <span class="hljs-string">'hello'</span> ./dir | xargs sed -i.orig <span class="hljs-string">'s/foo/bar/g'</span>
</code></pre>
<blockquote>
<p>옵션에 SUFFIX 를 사용할 때는 공백 없이 붙여야 합니다.<br>만약에 <code>-i</code>, <code>-r</code> 옵션 사용을 <code>-ir</code> 와같이 한다면 <code>r</code> 이 SUFFIX 가 되므로 주의해야 합니다.</p>
</blockquote>
<h4 id="followsymlinks">--follow-symlinks</h4>
<p><code>-i</code> 옵션을 사용하여 직접 파일을 저장할 경우 대상 파일이 symbolic link 이면
처리되는 방식에 차이가 있습니다.
다음은 <code>foo</code> 가 파일 <code>file.txt</code> 의 symbolic link 일 경우 --follow-symlinks 옵션을
사용 안 했을 때와 했을 때의 차이를 비교한 것입니다.</p>
<pre><code class="lang-bash">$ cat file.txt
<span class="hljs-number">1111111111</span>
$ ls <span class="hljs-operator">-l</span>
total <span class="hljs-number">4</span> <span class="hljs-comment"># foo 는 file.txt 의 symbolic link</span>
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">11</span> <span class="hljs-number">2020</span>-<span class="hljs-number">03</span>-<span class="hljs-number">21</span> <span class="hljs-number">10</span>:<span class="hljs-number">40</span> file.txt
lrwxrwxrwx <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">8</span> <span class="hljs-number">2020</span>-<span class="hljs-number">03</span>-<span class="hljs-number">21</span> <span class="hljs-number">10</span>:<span class="hljs-number">42</span> foo -> file.txt
..............................................................
$ sed -i <span class="hljs-string">'s/1/22/g'</span> foo
$ ls <span class="hljs-operator">-l</span>
total <span class="hljs-number">8</span> <span class="hljs-comment"># foo symbolic link 가 일반 파일로 변경된다.</span>
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">11</span> <span class="hljs-number">2020</span>-<span class="hljs-number">03</span>-<span class="hljs-number">21</span> <span class="hljs-number">10</span>:<span class="hljs-number">40</span> file.txt
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">21</span> <span class="hljs-number">2020</span>-<span class="hljs-number">03</span>-<span class="hljs-number">21</span> <span class="hljs-number">10</span>:<span class="hljs-number">44</span> foo
$ cat foo
<span class="hljs-number">22222222222222222222</span>
$ cat file.txt
<span class="hljs-number">1111111111</span>
<span class="hljs-comment"># 다음은 --follow-symlinks 옵션을 사용했을 경우</span>
$ sed --follow-symlinks -i <span class="hljs-string">'s/1/22/g'</span> foo
$ ls <span class="hljs-operator">-l</span>
total <span class="hljs-number">4</span> <span class="hljs-comment"># foo symbolic link 는 그대로이고 연결된 file.txt 가 변경된다.</span>
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">21</span> <span class="hljs-number">2020</span>-<span class="hljs-number">03</span>-<span class="hljs-number">21</span> <span class="hljs-number">10</span>:<span class="hljs-number">45</span> file.txt
lrwxrwxrwx <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">8</span> <span class="hljs-number">2020</span>-<span class="hljs-number">03</span>-<span class="hljs-number">21</span> <span class="hljs-number">10</span>:<span class="hljs-number">45</span> foo -> file.txt
$ cat file.txt
<span class="hljs-number">22222222222222222222</span>
<span class="hljs-comment">############### 다음은 -i 옵션에 suffix 를 사용했을 경우 #############</span>
$ sed -i.bak <span class="hljs-string">'s/1/22/g'</span> foo
$ ls <span class="hljs-operator">-l</span> <span class="hljs-comment"># sed 명령의 처리 결과가 foo 파일로 저장되고 foo.bak 은 symbolic link 가 된다.</span>
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">11</span> <span class="hljs-number">2018</span>-<span class="hljs-number">06</span>-<span class="hljs-number">21</span> <span class="hljs-number">23</span>:<span class="hljs-number">20</span> file.txt
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">21</span> <span class="hljs-number">2018</span>-<span class="hljs-number">07</span>-<span class="hljs-number">14</span> <span class="hljs-number">15</span>:<span class="hljs-number">36</span> foo
lrwxrwxrwx <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">8</span> <span class="hljs-number">2018</span>-<span class="hljs-number">07</span>-<span class="hljs-number">14</span> <span class="hljs-number">15</span>:<span class="hljs-number">35</span> foo.bak -> file.txt
<span class="hljs-comment"># 다음은 --follow-symlinks 옵션을 사용했을 경우</span>
$ sed -i.bak --follow-symlinks <span class="hljs-string">'s/1/22/g'</span> foo
$ ls <span class="hljs-operator">-l</span> <span class="hljs-comment"># foo symbolic link 는 그대로이고 연결된 file.txt 가 변경된다.</span>
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">21</span> <span class="hljs-number">2018</span>-<span class="hljs-number">07</span>-<span class="hljs-number">14</span> <span class="hljs-number">16</span>:<span class="hljs-number">06</span> file.txt
-rw-rw-r-- <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">11</span> <span class="hljs-number">2018</span>-<span class="hljs-number">07</span>-<span class="hljs-number">14</span> <span class="hljs-number">15</span>:<span class="hljs-number">44</span> file.txt.bak
lrwxrwxrwx <span class="hljs-number">1</span> mug896 mug896 <span class="hljs-number">8</span> <span class="hljs-number">2018</span>-<span class="hljs-number">07</span>-<span class="hljs-number">14</span> <span class="hljs-number">16</span>:<span class="hljs-number">04</span> foo -> file.txt
$ cat file.txt
<span class="hljs-number">22222222222222222222</span>
$ cat file.txt.bak
<span class="hljs-number">1111111111</span>
</code></pre>
</section>
</div>
</div>
</div>
<a href="./execute.html" class="navigation navigation-prev " aria-label="Previous page: Execute"><i class="fa fa-angle-left"></i></a>
<a href="./debugging.html" class="navigation navigation-next " aria-label="Next page: Debugging"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="gitbook/app.js"></script>
<script src="gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
<script src="gitbook/plugins/gitbook-plugin-search/search.js"></script>
<script src="gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
<script>
require(["gitbook"], function(gitbook) {
var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
gitbook.start(config);
});
</script>
</body>
</html>