![콘솔에서 패턴 검색 및 출력 출력](https://linux55.com/image/100515/%EC%BD%98%EC%86%94%EC%97%90%EC%84%9C%20%ED%8C%A8%ED%84%B4%20%EA%B2%80%EC%83%89%20%EB%B0%8F%20%EC%B6%9C%EB%A0%A5%20%EC%B6%9C%EB%A0%A5.png)
입력 파일은 다음과 같습니다.
{"key":"value";"ipaddress:"scrubbed";"id":"scrubbed"}
{"key1":"value";"ipaddress:"scrubbed";"id":"scrubbed"}
{"key2":"value";"ipaddress:"scrubbed";"id":"scrubbed"}
{"key3":"value";"ipaddress:"scrubbed";"id":"scrubbed"}
상상하다:
위 파일의 모든 입력줄의 IP 주소와 ID가 제거되었는지 확인해야 합니다.
콘솔에 인쇄될 예외 출력:
ip address and id got scrubbed in all the lines of input file
답변1
이는 "scrubbed" 값이 id 및 ipaddress에 대해서만 발생할 수 있다고 가정합니다. 그러나 아마도 최선의 해결책은 아닐 것입니다.
#!/bin/bash
flag=0
while read -r line
do
if [[ $(echo "$line" | grep -o -w scrubbed | wc -l) -ne 2 ]]
then
echo 'IP address and id NOT scrubbed in every line!'
echo "$line"
flag=1
break
fi
done < input.txt
if [[ $flag -ne 1 ]]
then
echo 'ip address and id got scrubbed in all the lines of input file'
fi
노트:grep -o
주어진 줄에 있는 모든 일치 항목을 인쇄합니다..