"Grep 파일 행 삭제"의 두 판 사이의 차이

(새 문서: ==개요== {{소문자}} ;grep 파일 행 삭제 * grep 자체에는 파일 저장 기능이 없다. 하지만, 리눅스 파이프 기능을 이용하여 파일로 저장할 수 있...)
 
7번째 줄: 7번째 줄:


<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
root@wsl:~$ cat a.txt
testuser@wsl:~$ cat a.txt
1 foo bar
1 foo bar
2 hello world
2 hello world
13번째 줄: 13번째 줄:
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
root@wsl:~$ cat a.txt | grep -v world
testuser@wsl:~$ cat a.txt | grep -v world
1 foo bar
1 foo bar
3 lorem ipsum
3 lorem ipsum
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
root@wsl:~$ cat a.txt | grep -v world > temp.txt
testuser@wsl:~$ cat a.txt | grep -v world > temp.txt
root@wsl:~$ cat temp.txt > a.txt
testuser@wsl:~$ cat temp.txt > a.txt
root@wsl:~$ cat a.txt
testuser@wsl:~$ cat a.txt
1 foo bar
1 foo bar
3 lorem ipsum
3 lorem ipsum

2024년 2월 19일 (월) 17:48 판

1 개요

grep 파일 행 삭제
  • grep 자체에는 파일 저장 기능이 없다. 하지만, 리눅스 파이프 기능을 이용하여 파일로 저장할 수 있긴 하다.
  • 그런데, 파이프 기능을 이용하더라도, 파일 내용을 처리 후에 그 원본 파일에 바로 저장할 수는 없다. (오류는 발생하지 않지만 파일 내용이 삭제된다 ㅠ)
  • 따라서 임시 파일에 저장한 다음 다시 원래 파일에 저장해야 한다.
testuser@wsl:~$ cat a.txt
1 foo bar
2 hello world
3 lorem ipsum
testuser@wsl:~$ cat a.txt | grep -v world
1 foo bar
3 lorem ipsum
testuser@wsl:~$ cat a.txt | grep -v world > temp.txt
testuser@wsl:~$ cat temp.txt > a.txt
testuser@wsl:~$ cat a.txt
1 foo bar
3 lorem ipsum

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}