선택한 정보를 한 TXT 파일에서 다른 TXT 파일로 이동

선택한 정보를 한 TXT 파일에서 다른 TXT 파일로 이동

config.txt와 template.txt라는 두 개의 txt 파일이 있습니다.

template.txt는 config.txt에서 관련 정보를 얻어야 합니다.

config.txt에 다음이 포함되어 있다고 가정합니다.

colour1: red
colour2: blue

template.txt에는 다음이 포함됩니다.

colour1:
colour2:

이 두 파일을 "링크"하여 template.txt가 config.txt의 해당 헤더에서 정보를 가져오도록 하는 것이 가능합니까?

템플릿.txt

colour1: red
colour2: blue

답변1

grep -f사용 사례에 따라 파일에서 config.txt줄을 검색 template.txt하면 일치하는 줄을 얻을 수 있습니다 .

즉:

$ cat config.txt
color1: red
color2: blue
color3: green
color4: purple
color5: orange
foo: bar
$ cat template.txt
color1:
color2:
color5:
$ grep -f template.txt config.txt
color1: red
color2: blue
color5: orange

참고하시기 바랍니다할 수 없다grep -f template.txt config.txt > template.txt실행하기 전에 쉘이 지워지므로 이 작업을 수행하십시오 template.txt. grep이 문제를 해결하려면 임시 파일을 사용해야 합니다.

관련 정보