![유사한 행을 나열하는 방법은 무엇입니까?](https://linux55.com/image/40613/%EC%9C%A0%EC%82%AC%ED%95%9C%20%ED%96%89%EC%9D%84%20%EB%82%98%EC%97%B4%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
구분 기호는 "";
입력하다:
foo#foo_ehh113#The password of user 111 will expire within the next seven d
foo#foo_ehh204#The password of user 111 will expire within the next seven d
sadf#sadf this is a sample_text
foo#foo_ehh204#The password of user 222 will expire within the next seven da
foo - moreeee test
foo#foo_ehh113#The password of user 222 will expire within the next seven da
foo#foo_ehh113#The password of user 333 will expire within the next seven day
ldr#ldr_another sample text
foo#foo_ehh204#The password of user 333 will expire within the next seven day
산출:
foo#foo_ehh113#The password of user 111 will expire within the next seven d
foo#foo_ehh204#The password of user 111 will expire within the next seven d
foo#foo_ehh204#The password of user 222 will expire within the next seven da
foo#foo_ehh113#The password of user 222 will expire within the next seven da
foo#foo_ehh113#The password of user 333 will expire within the next seven day
foo#foo_ehh204#The password of user 333 will expire within the next seven day
예를 들어 주어진 줄에 비슷한 단어가 있습니다.
The
password
of
user
will
expire
within
the
내 질문:어느 정도 유사한 행만 출력하는 방법이 있나요? 전임자. 8개의 단어와 일치합니다.
이를 감지할 수 있는 쉘 스크립트가 있습니까?
답변1
텍스트를 순차적으로 일치시키려면 다음을 시도해 볼 수 있습니다.
$ grep 'The.*password.*of.*user.*will.*expire.*within.*the' file
foo#foo_ehh113#The password of user 111 will expire within the next seven d
foo#foo_ehh204#The password of user 111 will expire within the next seven d
foo#foo_ehh204#The password of user 222 will expire within the next seven da
foo#foo_ehh113#The password of user 222 will expire within the next seven da
foo#foo_ehh113#The password of user 333 will expire within the next seven day
foo#foo_ehh204#The password of user 333 will expire within the next seven day
텍스트 그룹(group.txt라는 이름)을 포함하는 파일이 있는 경우 다음을 사용할 수 있습니다.
$ grep $(printf "%s.*" $(cat group.txt)) file
답변2
명령줄에 next를 입력하여 원하는 만큼 키워드를 제공할 수 있습니다.
grep -E "one|two|three" file.txt
소스가 dmesg인 경우 다음을 수행합니다.
dmesg | grep -E "one|two|three"